private DynamicMethodBody ClientProxyMethodBody(DynamicMethodBody methodBody, MethodInfo methodInfoToImplement) { var proxyClientClassConstructor = GetProxyClientConstructorInfo(); var proxyClientClassConstructorParameters = proxyClientClassConstructor.Parameters().ToArray(); var invokeMethod = typeof(Action <OperationContext>).Method("Invoke", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var oprerationContextCurrentGetMethod = typeof(OperationContext).Method("get_Current", BindingFlags.Static | BindingFlags.Public); CreateClientProxy(methodBody, proxyClientClassConstructor, proxyClientClassConstructorParameters) .Stloc(SERVICE_CLIENT_VARIABLE_NAME) .Ldloc(SERVICE_CLIENT_VARIABLE_NAME) .CallGet <ClientBase <TServiceInterface> >("InnerChannel") .Newobj <OperationContextScope>(typeof(IContextChannel)) .Stloc(OPERATION_CONTEXT_SCOPE_VARIABLE_NAME) .Call(oprerationContextCurrentGetMethod) .Stloc(OPERATION_CONTEXT_VARIABLE_NAME) .Ldarg(0) .Ldfld(BEFORE_OPERATION_CALLBACK_FIELD_NAME) .Ldloc(OPERATION_CONTEXT_VARIABLE_NAME) .Callvirt(invokeMethod) .Ldloc(SERVICE_CLIENT_VARIABLE_NAME) .Callvirt(m_ClientChannelPropertyInfo.GetGetMethod()) .Repeater(1, methodInfoToImplement.Parameters().Count, 1, (i, m) => m.Ldarg((uint)i)) .Callvirt(methodInfoToImplement) .Stloc(METHOD_RESULT_VARIABLE_NAME) .Ldarg(0) .Ldfld(AFTER_OPERATION_CALLBACK_FIELD_NAME) .Ldloc(OPERATION_CONTEXT_VARIABLE_NAME) .Callvirt(invokeMethod); return(methodBody); }
private static DynamicMethodBody EmitAfterExecuteCall( this DynamicMethodBody body, bool condition, MethodInfo method) { if (!condition) { return(body); } var afterExecuteMi = typeof(IProxyMonitor) .GetMethod("AfterExecute"); if (method.ReturnType != typeof(void)) { body .Stloc(0) .Ldloc(0) .Box(method.ReturnType); } else { body.Ldnull(); } body .Call(afterExecuteMi); if (method.ReturnType != typeof(void)) { body.Ldloc(0); } return(body); }
public static ParseResult Parse(string expression, DynamicMethodBody methodBody = null) { return(new Parser( new ExpressionScanner().Scan(expression), methodBody ).Parse()); }
private void InitConstructorBuilder(Type[] constructorArgumentTypes) { _constructorBuilderField = DynamicTypeInfo.TypeBuilder .DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, constructorArgumentTypes); _reflectionILEmitterField = new ReflectionILEmitter(_constructorBuilderField.GetILGenerator()); _body = new DynamicMethodBody(this); }
public static void Parse(string expression, DynamicMethodBody methodBody = null) { new Parser( new ExpressionScanner().Scan(expression), methodBody ).Parse(); }
private static DynamicMethodBody EmitConcreteMethodCall( this DynamicMethodBody body, MethodInfo method) { var parameters = method.GetParameters(); return(body .Ldarg(0) .Ldfld("__concreteinstance") .Repeater(0, parameters.Length - 1, 1, (index, b) => b .Ldarg(parameters[index].Name) ) .Call(method)); }
private static DynamicMethodBody CreateClientProxy( DynamicMethodBody methodBody, ConstructorInfo proxyClientClassConstructor, ParameterInfo[] proxyClientClassConstructorParameters) { return(methodBody.Repeater(0, proxyClientClassConstructorParameters.Length - 1, 1, (i, repeaterMethodBody) => repeaterMethodBody .Ldarg(0) .Ldfld(SERVICE_CLIENT_CONSTRUCTOR_PARAMETERS_FIELD_NAME) .LdcI4(i) .Ldelem_Ref() .UnboxAny(proxyClientClassConstructorParameters[i].ParameterType)) .Newobj(proxyClientClassConstructor)); }
private static DynamicMethodBody EmitBeforeExecuteCall( this DynamicMethodBody body, bool condition, MethodInfo method ) { if (!condition) { return(body); } var beforeExecuteMi = typeof(IProxyMonitor) .GetMethod("BeforeExecute"); var parameters = method.GetParameters(); return(body .Ldarg(0).Dup() .Ldfld("__proxymonitor") .Ldstr(method.Name) .Newarr(typeof(object), parameters.Length) .EmitIf(parameters.Length > 0, b => b .Stloc("parameters") .Repeater(0, parameters.Length - 1, 1, (index, b1) => b1 .Ldloc("parameters") .Ldc(index) .Ldarg((uint)(index + 1)) .Box(parameters[index].ParameterType) .Emit(OpCodes.Stelem_Ref) ) .Ldloc("parameters") ) .Call(beforeExecuteMi) // .Ldfld("__proxymonitor") .Ldstr(method.Name)); }
public DynamicMethodInfo() { Body = new DynamicMethodBody(this); MethodName = "DynMethod"; }
public DynamicMethodInfo(ILEmitter emitter) { Body = new DynamicMethodBody(this); _emitter = emitter; }
public override void Emit(DynamicMethodBody generator) { generator.Ldc(Value); }
// ReSharper restore InconsistentNaming public ILEmitterVisitor(DynamicMethodBody dmb) { IL = dmb; }
internal Parser(IEnumerable <Token> source, DynamicMethodBody body = null) { Source = source; MethodBody = body; }
public override void Emit(DynamicMethodBody generator) { Parser.Parse(Expression, generator); }
public override void Emit(DynamicMethodBody generator) { generator.Expression(Expression); }
public abstract void Emit(DynamicMethodBody generator);