private AssignStatement SetDelegate(LocalReference localDelegate, ReferenceExpression localTarget, Type closedDelegateType, MethodInfo closedMethodOnTarget) { var delegateCreateDelegate = new MethodInvocationExpression( null, DelegateMethods.CreateDelegate, new TypeTokenExpression(closedDelegateType), localTarget, new MethodTokenExpression(closedMethodOnTarget)); return new AssignStatement(localDelegate, new ConvertExpression(closedDelegateType, delegateCreateDelegate)); }
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 (var i = 0; i < parameters.Length; i++) { if (!parameters[i].ParameterType.IsByRef) { continue; } emitter.CodeBuilder.AddStatement(AssignArgument(dereferencedArguments, i, arguments)); } }
public LocalReference DeclareLocal(Type type) { var local = new LocalReference(type); ilmarkers.Add(local); return local; }
public ByRefReference(LocalReference localReference) : base(localReference.Type) { this.localReference = localReference; }
private static LocalReference StoreInvocationArgumentsInLocal(MethodEmitter emitter, LocalReference invocation) { var invocationArgs = emitter.CodeBuilder.DeclareLocal(typeof(object[])); emitter.CodeBuilder.AddStatement(GetArguments(invocationArgs, invocation)); return invocationArgs; }
private static AssignStatement GetArguments(LocalReference invocationArgs, LocalReference invocation) { return new AssignStatement(invocationArgs, new MethodInvocationExpression(invocation, InvocationMethods.GetArguments)); }
private static AssignStatement AssignArgument(TypeReference[] dereferencedArguments, int i, LocalReference invocationArgs) { return new AssignStatement(dereferencedArguments[i], Argument(i, invocationArgs, dereferencedArguments)); }
private static ConvertExpression Argument(int i, LocalReference invocationArgs, TypeReference[] arguments) { return new ConvertExpression(arguments[i].Type, new LoadRefArrayElementExpression(i, invocationArgs)); }