protected override void ImplementProceed(MethodDefinition methodInfo, MethodBody methodBody, ILProcessor il, FieldReference methodInfoField, MethodReference proceed, Action <ILProcessor> emitProceedTarget, MethodReference proceedTargetMethod, OpCode proceedOpCode)
            {
                if (Method.IsAbstract)
                {
                    // Always return the default value
                    CecilExtensions.CreateDefaultMethodImplementation(Method, il);
                }
                else
                {
                    // Load handler (consumed by call to invokeMethod near the end)
                    EmitProxyFromProceed(il);
                    il.Emit(OpCodes.Callvirt, ClassWeaver.Context.ReverseProxyGetInvocationHandlerMethod);

                    // Put Invocation onto the stack
                    il.Emit(OpCodes.Ldarg_0);                                                            // invocation
                    il.Emit(OpCodes.Call, ClassWeaver.Context.InvocationGetArguments);                   // .Arguments
                    il.Emit(OpCodes.Ldc_I4, Method.Parameters.Count);                                    // Array index
                    il.Emit(OpCodes.Ldelem_Any, ClassWeaver.Context.ModuleDefinition.TypeSystem.Object); // Load element
                    il.Emit(OpCodes.Castclass, InvocationType);                                          // Cast it into specific invocation subclass

                    // Invoke handler
                    il.Emit(OpCodes.Callvirt, InvokeMethod);

                    // Return from method
                    il.Emit(OpCodes.Ret);
                }
            }
示例#2
0
 protected override void ImplementProceed(MethodDefinition methodInfo, MethodBody methodBody, ILProcessor il, FieldReference methodInfoField, MethodReference proceed, Action <ILProcessor> emitProceedTarget, MethodReference proceedTargetMethod, OpCode proceedOpCode)
 {
     if (methodInfo.IsAbstract)
     {
         CecilExtensions.CreateDefaultMethodImplementation(methodInfo, il);
     }
     else
     {
         base.ImplementProceed(methodInfo, methodBody, il, methodInfoField, proceed, emitProceedTarget, proceedTargetMethod, proceedOpCode);
     }
 }
        protected override MethodDefinition GetStaticConstructor()
        {
            var staticConstructor = ProxyType.GetStaticConstructor();

            if (staticConstructor == null)
            {
                staticConstructor = CecilExtensions.CreateStaticConstructor(ProxyType);
            }
            else
            {
                staticConstructor.Body.Instructions.RemoveAt(staticConstructor.Body.Instructions.Count - 1);
            }
            return(staticConstructor);
        }
示例#4
0
            protected override void ImplementProceed(MethodDefinition methodInfo, MethodBody methodBody, ILProcessor il, FieldReference methodInfoField, MethodReference proceed, Action <ILProcessor> emitProceedTarget, MethodReference proceedTargetMethod, OpCode proceedOpCode)
            {
                // If T is an interface, then we want to check if target is null; if so, we want to just return the default value
                var targetNotNull = il.Create(OpCodes.Nop);

                EmitProxyFromProceed(il);
                il.Emit(OpCodes.Ldfld, ClassWeaver.Target);  // Load "target" from "this"
                il.Emit(OpCodes.Brtrue, targetNotNull);      // If target is not null, jump below
                CecilExtensions.CreateDefaultMethodImplementation(methodBody.Method, il);

                il.Append(targetNotNull);                    // Mark where the previous branch instruction should jump to

                base.ImplementProceed(methodInfo, methodBody, il, methodInfoField, proceed, emitProceedTarget, proceedTargetMethod, proceedOpCode);
            }
示例#5
0
        public override void Execute()
        {
            CecilExtensions.LogError   = LogError;
            CecilExtensions.LogInfo    = LogInfo;
            CecilExtensions.LogWarning = LogWarning;
            CecilExtensions.Initialize(ModuleDefinition);

            var propertyWeaver = new SexyProxyWeaver
            {
                ModuleDefinition = ModuleDefinition,
                LogInfo          = LogInfo,
                LogWarning       = LogWarning,
                LogError         = LogError
            };

            propertyWeaver.Execute();
        }
            protected override void ImplementProceed(MethodDefinition methodInfo, MethodBody methodBody, ILProcessor il, FieldReference methodInfoField, MethodReference proceed, Action <ILProcessor> emitProceedTarget, MethodReference proceedTargetMethod, OpCode proceedOpCode)
            {
                if (methodInfo.IsAbstract)
                {
                    CecilExtensions.CreateDefaultMethodImplementation(methodInfo, il);
                }
                else
                {
                    var targetNotNull = il.Create(OpCodes.Nop);
                    EmitProxyFromProceed(il);
                    il.Emit(OpCodes.Ldfld, target);              // Load "target" from "this"
                    il.Emit(OpCodes.Brtrue, targetNotNull);      // If target is not null, jump below

                    base.ImplementProceed(methodInfo, methodBody, il, methodInfoField, proceed, _ => EmitProxyFromProceed(il), callBaseMethod, OpCodes.Call);

                    il.Append(targetNotNull);                    // Mark where the previous branch instruction should jump to

                    base.ImplementProceed(methodInfo, methodBody, il, methodInfoField, proceed, emitProceedTarget, proceedTargetMethod, proceedOpCode);
                }
            }