Example #1
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));
        }
Example #2
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));
        }
 /// <summary>
 /// start definition of constructor method body with calling to base class default constructor
 /// </summary>
 public DynamicMethodBody BodyDefinitionWithDefaultBaseCtor()
 {
     _body.Ldarg(0)
     .Call(BaseConstructor());
     return(_body);
 }