public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
        {
            LocalBuilder           methodLocalBuilder    = null;
            FieldBuilder           contractFieldBuilder  = null;
            LocalBuilder           aspectArgLocalBuilder = null;
            AspectArgsMethodWeaver methodWeaver          = null;
            ConstructorInfo        ctorInterceptionArgs  = null;

            methodLocalBuilder = LocalBuilderRepository.Declare(() => {
                return(ilGenerator.DeclareLocal(typeof(MethodInfo)));
            });

            aspectArgLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
            contractFieldBuilder  = WeavingSettings.TypeDefinition.GetFieldBuilder(WeavingSettings.ContractType);
            methodWeaver          = new AspectArgsMethodWeaver(Member, methodLocalBuilder, Parameters, aspectWeavingSettings);
            methodWeaver.Weave(ilGenerator);
            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.EmitLoadLocal(methodLocalBuilder);
            ctorInterceptionArgs = ArgumentType.GetConstructors()[0];

            Parameters.ForEach(1, (parameter, i) => {
                ilGenerator.EmitLoadArg(i);

                if (parameter.IsByRef)
                {
                    ilGenerator.Emit(OpCodes.Ldind_I4);
                }
            });

            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);

            return(aspectArgLocalBuilder);
        }
        public override void Weave(ILGenerator ilGenerator)
        {
            LocalBuilder argsImplLocalBuilder = null;
            var          ctorInterceptionArgs = ArgumentType.GetConstructors()[0];
            var          aspectArgsType       = Member.ToAspectArgumentContract();
            var          methodProperty       = aspectArgsType.GetProperty("Method");

            argsImplLocalBuilder = LocalBuilderRepository.GetOrDeclare(ArgumentType, () => {
                return(ilGenerator.DeclareLocal(ArgumentType));
            });

            ilGenerator.EmitLoadArg(1);
            ilGenerator.Emit(OpCodes.Ldind_Ref);
            WeaveAspectArg(ilGenerator);
            ilGenerator.Emit(OpCodes.Callvirt, methodProperty.GetGetMethod());
            ilGenerator.Emit(OpCodes.Ldsfld, bindingsDependency);

            Parameters.ForEach(1, (parameter, i) => {
                var property = aspectArgsType.GetProperty("Arg{0}".Fmt(i));

                WeaveAspectArg(ilGenerator);
                ilGenerator.Emit(OpCodes.Callvirt, property.GetGetMethod());
            });

            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(argsImplLocalBuilder);
        }
        public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
        {
            LocalBuilder    propertyLocalBuilder          = null;
            FieldBuilder    contractFieldBuilder          = null;
            LocalBuilder    aspectArgLocalBuilder         = null;
            ConstructorInfo ctorInterceptionArgs          = null;
            AbstractAspectPropertyArgsWeaver methodWeaver = null;

            propertyLocalBuilder = LocalBuilderRepository.Declare(() => {
                return(ilGenerator.DeclareLocal(typeof(PropertyInfo)));
            });

            ctorInterceptionArgs  = ArgumentType.GetConstructors()[0];
            aspectArgLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
            contractFieldBuilder  = WeavingSettings.TypeDefinition.GetFieldBuilder(WeavingSettings.ContractType);
            methodWeaver          = new AspectArgsSetPropertyWeaver(Member, propertyLocalBuilder, aspectWeavingSettings);
            methodWeaver.Weave(ilGenerator);
            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.EmitLoadLocal(propertyLocalBuilder);
            ilGenerator.Emit(OpCodes.Ldsfld, BindingsDependency);
            ilGenerator.EmitLoadArg(1);
            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);

            return(aspectArgLocalBuilder);
        }
Ejemplo n.º 4
0
        public override void Weave(ILGenerator ilGenerator)
        {
            FieldBuilder contractFieldBuilder = null;
            var          declaredLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
            var          ctorInterceptionArgs = ArgumentType.GetConstructors()[0];
            var          argsLocalBuilder     = LocalBuilderRepository.Get(previousAspectArgType);
            var          methodPropoertyInfo  = previousAspectArgType.GetProperty("Method");

            LocalBuilderRepository.Add(declaredLocalBuilder);
            contractFieldBuilder = WeavingSettings.TypeDefinition.GetFieldBuilder(WeavingSettings.ContractType);
            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.EmitLoadLocal(argsLocalBuilder);
            ilGenerator.Emit(OpCodes.Callvirt, methodPropoertyInfo.GetGetMethod());
            ilGenerator.Emit(OpCodes.Ldsfld, BindingsDependency);

            Parameters.ForEach(1, (parameter, i) => {
                var property = previousAspectArgType.GetProperty("Arg{0}".Fmt(i));

                ilGenerator.EmitLoadLocal(argsLocalBuilder);
                ilGenerator.Emit(OpCodes.Callvirt, property.GetGetMethod());
            });

            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(declaredLocalBuilder);
        }
Ejemplo n.º 5
0
        public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
        {
            var aspectArgLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
            var eventArgumentContract = Member.ToEventArgumentContract();
            var ctorInterceptionArgs  = ArgumentType.GetConstructors().Single(ctor => ctor.GetParameters().Length != 0);
            var eventBrokerProperty   = eventArgumentContract.GetProperty("EventBroker");
            var eventBrokerType       = eventBrokerProperty.PropertyType;
            var handlerType           = eventBrokerType.GetGenericArguments().First();
            var parameters            = handlerType.GetInvokeMethod().GetParameters();

            ilGenerator.EmitLoadArg(1);
            ilGenerator.Emit(OpCodes.Ldind_Ref);
            ilGenerator.EmitLoadArg(3);
            ilGenerator.Emit(OpCodes.Callvirt, eventArgumentContract.GetProperty("Event").GetGetMethod());
            ilGenerator.EmitLoadArg(3);
            ilGenerator.Emit(OpCodes.Callvirt, eventArgumentContract.GetProperty("Handler").GetGetMethod());
            ilGenerator.Emit(OpCodes.Ldsfld, BindingsDependency);
            ilGenerator.EmitLoadArg(3);
            ilGenerator.Emit(OpCodes.Callvirt, eventBrokerProperty.GetGetMethod());

            parameters.ForEach(1, (arg, i) => {
                var property = ArgumentType.GetProperty("Arg{0}".Fmt(i));

                ilGenerator.EmitLoadArg(3);
                ilGenerator.Emit(OpCodes.Callvirt, property.GetGetMethod());
            });

            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);

            return(aspectArgLocalBuilder);
        }
Ejemplo n.º 6
0
        public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
        {
            var typeDefinition                 = (IAspectTypeDefinition)WeavingSettings.TypeDefinition;
            var aspectArgLocalBuilder          = ilGenerator.DeclareLocal(ArgumentType);
            var eventLocalBuilder              = ilGenerator.DeclareLocal(typeof(EventInfo));
            var contractFieldBuilder           = typeDefinition.GetFieldBuilder(WeavingSettings.ContractType);
            var eventArgumentContract          = Member.ToEventArgumentContract();
            var eventBrokerProperty            = eventArgumentContract.GetProperty("EventBroker");
            var eventBrokerType                = eventBrokerProperty.PropertyType;
            var handlerType                    = eventBrokerType.GetGenericArguments().First();
            var delegateLocalBuilder           = ilGenerator.DeclareLocal(handlerType);
            var delegateCtor                   = handlerType.GetConstructor(new[] { typeof(object), typeof(IntPtr) });
            var eventBrokerFieldBuilder        = typeDefinition.GetEventFieldBuilder(Member.Name, eventBrokerType);
            var eventBrokerFieldTypeDefinition = typeDefinition.GetEventBrokerFielTypeDefinition(Member);
            var ctorInterceptionArgs           = ArgumentType.GetConstructors().Single(ctor => ctor.GetParameters().Length != 0);
            var parameters = handlerType.GetInvokeMethod().GetParameters();

            ilGenerator.EmitLoadArg(1);
            ilGenerator.Emit(OpCodes.Ldftn, eventBrokerFieldTypeDefinition.Event.EventHandlerType.GetInvokeMethod());
            ilGenerator.Emit(OpCodes.Newobj, delegateCtor);
            ilGenerator.EmitStoreLocal(delegateLocalBuilder);
            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.Emit(OpCodes.Callvirt, typeof(object).GetMethod("GetType"));
            ilGenerator.Emit(OpCodes.Ldstr, Member.Name);
            ilGenerator.Emit(OpCodes.Callvirt, typeof(Type).GetMethod("GetEvent", new[] { typeof(string) }));
            ilGenerator.EmitStoreLocal(eventLocalBuilder);
            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.EmitLoadLocal(eventLocalBuilder);
            ilGenerator.EmitLoadLocal(delegateLocalBuilder);
            ilGenerator.Emit(OpCodes.Ldsfld, BindingsDependency);
            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, eventBrokerFieldBuilder);

            parameters.ForEach(1, (arg, i) => {
                var property = ArgumentType.GetProperty("Arg{0}".Fmt(i));

                ilGenerator.EmitLoadArg(1);
                ilGenerator.Emit(OpCodes.Callvirt, property.GetGetMethod());
            });

            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);

            return(aspectArgLocalBuilder);
        }
        public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
        {
            LocalBuilder    aspectArgLocalBuilder = null;
            ConstructorInfo ctorInterceptionArgs  = null;
            var             aspectArgsType        = Member.ToPropertyArgumentContract();

            ctorInterceptionArgs  = ArgumentType.GetConstructors()[0];
            aspectArgLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
            ilGenerator.EmitLoadArg(1);
            ilGenerator.Emit(OpCodes.Ldind_Ref);
            ilGenerator.EmitLoadArg(2);
            ilGenerator.Emit(OpCodes.Callvirt, aspectArgsType.GetProperty("Property").GetGetMethod());
            ilGenerator.Emit(OpCodes.Ldsfld, bindingsDependency);
            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);

            return(aspectArgLocalBuilder);
        }