本文整理汇总了C#中Castle.DynamicProxy.Generators.Emitters.MethodEmitter类的典型用法代码示例。如果您正苦于以下问题:C# MethodEmitter类的具体用法?C# MethodEmitter怎么用?C# MethodEmitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodEmitter类属于Castle.DynamicProxy.Generators.Emitters命名空间,在下文中一共展示了MethodEmitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImplementInvokeMethodOnTarget
protected override void ImplementInvokeMethodOnTarget(AbstractTypeEmitter invocation, ParameterInfo[] parameters, MethodEmitter invokeMethodOnTarget, Reference targetField)
{
invokeMethodOnTarget.CodeBuilder.AddStatement(
new ExpressionStatement(
new MethodInvocationExpression(SelfReference.Self, InvocationMethods.EnsureValidTarget)));
base.ImplementInvokeMethodOnTarget(invocation, parameters, invokeMethodOnTarget, targetField);
}
示例2: GetCallbackMethodInvocation
public MethodInvocationExpression GetCallbackMethodInvocation(AbstractTypeEmitter invocation, Expression[] args,
Reference targetField,
MethodEmitter invokeMethodOnTarget)
{
var @delegate = GetDelegate(invocation, invokeMethodOnTarget);
return new MethodInvocationExpression(@delegate, GetCallbackMethod(), args);
}
示例3: GetCallbackMethodInvocation
public MethodInvocationExpression GetCallbackMethodInvocation(AbstractTypeEmitter invocation, Expression[] args, Reference targetField, MethodEmitter invokeMethodOnTarget)
{
var allArgs = GetAllArgs(args, targetField);
var @delegate = (Reference)invocation.GetField("delegate");
return new MethodInvocationExpression(@delegate, GetCallbackMethod(), allArgs);
}
示例4: CreateAddMethod
public MethodEmitter CreateAddMethod(MethodAttributes atts)
{
if (addMethod != null)
{
throw new InvalidOperationException("An add method exists");
}
addMethod = typeEmitter.CreateMethod("add_" + name, atts);
return addMethod;
}
示例5: CreateRemoveMethod
public MethodEmitter CreateRemoveMethod(MethodAttributes atts)
{
if (removeMethod != null)
{
throw new InvalidOperationException("A remove method exists");
}
removeMethod = typeEmitter.CreateMethod("remove_" + name, atts);
return removeMethod;
}
示例6: CreateAddMethod
public MethodEmitter CreateAddMethod(string addMethodName, MethodAttributes attributes, MethodInfo methodToOverride)
{
if (addMethod != null)
{
throw new InvalidOperationException("An add method exists");
}
addMethod = new MethodEmitter(typeEmitter, addMethodName, attributes, methodToOverride);
return addMethod;
}
示例7: CreateRemoveMethod
public MethodEmitter CreateRemoveMethod(string removeMethodName, MethodAttributes attributes,
MethodInfo methodToOverride)
{
if (removeMethod != null)
{
throw new InvalidOperationException("A remove method exists");
}
removeMethod = new MethodEmitter(typeEmitter, removeMethodName, attributes, methodToOverride);
return removeMethod;
}
示例8: GetDelegate
private Reference GetDelegate(AbstractTypeEmitter invocation, MethodEmitter invokeMethodOnTarget)
{
var closedDelegateType = delegateType.MakeGenericType(invocation.GenericTypeParams);
var localReference = invokeMethodOnTarget.CodeBuilder.DeclareLocal(closedDelegateType);
var closedMethodOnTarget = method.MethodOnTarget.MakeGenericMethod(invocation.GenericTypeParams);
var localTarget = new ReferenceExpression(targetReference);
invokeMethodOnTarget.CodeBuilder.AddStatement(
SetDelegate(localReference, localTarget, closedDelegateType, closedMethodOnTarget));
return localReference;
}
示例9: CreateGetMethod
public MethodEmitter CreateGetMethod(string name, MethodAttributes attrs, MethodInfo methodToOverride, params Type[] parameters)
{
if (getMethod != null)
{
throw new InvalidOperationException("A get method exists");
}
getMethod = new MethodEmitter(parentTypeEmitter, name, attrs, methodToOverride);
return getMethod;
}
示例10: BuildProxiedMethodBody
protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class,
ProxyGenerationOptions options, INamingScope namingScope)
{
var targetReference = getTargetReference(@class, MethodToOverride);
emitter.CodeBuilder.AddStatement(
new ExpressionStatement(
new IfNullExpression(targetReference, IfNull(emitter.ReturnType), IfNotNull(targetReference))));
return emitter;
}
示例11: BuildProxiedMethodBody
protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope)
{
var targetReference = getTargetReference(@class, MethodToOverride);
var arguments = ArgumentsUtil.ConvertToArgumentReferenceExpression(MethodToOverride.GetParameters());
emitter.CodeBuilder.AddStatement(new ReturnStatement(
new MethodInvocationExpression(
targetReference,
MethodToOverride,
arguments) { VirtualCall = true }));
return emitter;
}
示例12: InitOutParameters
private void InitOutParameters(MethodEmitter emitter, ParameterInfo[] parameters)
{
for (var index = 0; index < parameters.Length; index++)
{
var parameter = parameters[index];
if (parameter.IsOut)
{
emitter.CodeBuilder.AddStatement(
new AssignArgumentStatement(new ArgumentReference(parameter.ParameterType, index + 1),
new DefaultValueExpression(parameter.ParameterType)));
}
}
}
示例13: BuildProxiedMethodBody
protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope)
{
InitOutParameters(emitter, MethodToOverride.GetParameters());
if (emitter.ReturnType == typeof(void))
{
emitter.CodeBuilder.AddStatement(new ReturnStatement());
}
else
{
emitter.CodeBuilder.AddStatement(new ReturnStatement(new DefaultValueExpression(emitter.ReturnType)));
}
return emitter;
}
示例14: CopyOutAndRefParameters
public static void CopyOutAndRefParameters(TypeReference[] dereferencedArguments, LocalReference invocation, MethodInfo method, MethodEmitter emitter)
{
var parameters = method.GetParameters();
if (!ArgumentsUtil.IsAnyByRef(parameters))
{
return; //saving the need to create locals if there is no need
}
var arguments = StoreInvocationArgumentsInLocal(emitter, invocation);
for (int i = 0; i < parameters.Length; i++)
{
if (!parameters[i].ParameterType.IsByRef) continue;
emitter.CodeBuilder.AddStatement(AssignArgument(dereferencedArguments, i, arguments));
}
}
示例15: CreateGetMethod
public MethodEmitter CreateGetMethod(string name, MethodAttributes attrs, params Type[] parameters)
{
if (getMethod != null)
{
throw new InvalidOperationException("A get method exists");
}
if (parameters.Length == 0)
{
getMethod = new MethodEmitter(parentTypeEmitter, name, attrs);
}
else
{
getMethod = new MethodEmitter(parentTypeEmitter, name,
attrs,
ReturnType,
parameters);
}
return getMethod;
}