예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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);
        }
예제 #5
0
 public static void Parse(string expression,
                          DynamicMethodBody methodBody = null)
 {
     new Parser(
         new ExpressionScanner().Scan(expression),
         methodBody
         ).Parse();
 }
예제 #6
0
        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));
        }
예제 #7
0
 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));
 }
예제 #8
0
        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));
        }
예제 #9
0
 public DynamicMethodInfo()
 {
     Body       = new DynamicMethodBody(this);
     MethodName = "DynMethod";
 }
예제 #10
0
 public DynamicMethodInfo(ILEmitter emitter)
 {
     Body     = new DynamicMethodBody(this);
     _emitter = emitter;
 }
예제 #11
0
 public override void Emit(DynamicMethodBody generator)
 {
     generator.Ldc(Value);
 }
예제 #12
0
// ReSharper restore InconsistentNaming

        public ILEmitterVisitor(DynamicMethodBody dmb)
        {
            IL = dmb;
        }
예제 #13
0
 internal Parser(IEnumerable <Token> source,
                 DynamicMethodBody body = null)
 {
     Source     = source;
     MethodBody = body;
 }
예제 #14
0
 public override void Emit(DynamicMethodBody generator)
 {
     Parser.Parse(Expression, generator);
 }
예제 #15
0
 public override void Emit(DynamicMethodBody generator)
 {
     generator.Expression(Expression);
 }
예제 #16
0
 public abstract void Emit(DynamicMethodBody generator);