当前位置: 首页>>代码示例>>C#>>正文


C# ILGenerator.EmitLoadArg方法代码示例

本文整理汇总了C#中System.Reflection.Emit.ILGenerator.EmitLoadArg方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.EmitLoadArg方法的具体用法?C# ILGenerator.EmitLoadArg怎么用?C# ILGenerator.EmitLoadArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.ILGenerator的用法示例。


在下文中一共展示了ILGenerator.EmitLoadArg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildArguments

        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;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:32,代码来源:BindingEventInterceptionArgumentsWeaver.cs

示例2: EmitConstructorBody

        protected override void EmitConstructorBody(ILGenerator ilGenerator)
        {
            var compositeTypeDefinition = (IAspectTypeDefinition)typeDefinition;

            base.EmitConstructorBody(ilGenerator);

            compositeTypeDefinition.EventBrokerFieldTypeDefinitions.ForEach(fieldTypeDefinition => {
                var contractType = fieldTypeDefinition.Event.DeclaringType;
                var contractField = compositeTypeDefinition.GetFieldBuilder(contractType);
                var eventBrokerCtor = fieldTypeDefinition.EventBrokerType.GetConstructors()[0];
                var delegateCtor = fieldTypeDefinition.EventBrokerDelegateType.GetConstructor(new[] { typeof(object), typeof(IntPtr) });
                var typeOfType = typeof(Type);

                ilGenerator.EmitLoadArg(0);
                ilGenerator.EmitLoadArg(0);
                ilGenerator.Emit(OpCodes.Ldfld, contractField);
                ilGenerator.Emit(OpCodes.Ldtoken, contractType);
                ilGenerator.Emit(OpCodes.Call, typeOfType.GetMethod("GetTypeFromHandle"));
                ilGenerator.Emit(OpCodes.Ldstr, fieldTypeDefinition.Event.Name);
                ilGenerator.Emit(OpCodes.Call, typeOfType.GetMethod("GetEvent", new[] { typeof(string) }));
                ilGenerator.EmitLoadArg(0);
                ilGenerator.Emit(OpCodes.Ldftn, fieldTypeDefinition.InvokeMethodBuilder);
                ilGenerator.Emit(OpCodes.Newobj, delegateCtor);
                ilGenerator.Emit(OpCodes.Newobj, eventBrokerCtor);
                ilGenerator.Emit(OpCodes.Stfld, fieldTypeDefinition.FieldBuilder);
            });
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:27,代码来源:CompositeWeavingStrategy.cs

示例3: BuildArguments

        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;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:27,代码来源:TopSetPropertyInterceptionArgumentsWeaver.cs

示例4: Weave

        public override void Weave(ILGenerator ilGenerator)
        {
            var contractFieldBuilder = weavingSettings.TypeDefinition.GetFieldBuilder(weavingSettings.ContractType);

            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.EmitLoadArg(1);
            ilGenerator.Emit(OpCodes.Call, Method);
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:9,代码来源:AbstractAddRemoveEventMethodScopeWeaver.cs

示例5: Weave

        public override void Weave(ILGenerator ilGenerator)
        {
            FieldBuilder fieldBuilder = TypeDefinition.GetFieldBuilder(ContractType);

            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
            ilGenerator.EmitLoadArg(1);
            ilGenerator.Emit(OpCodes.Callvirt, Method);
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:9,代码来源:SetPropertyDecoratorScopeWeaver.cs

示例6: Weave

        public override void Weave(ILGenerator ilGenerator)
        {
            var aspectArgsType = @event.ToEventArgumentContract();
            var eventBrokerProperty = aspectArgsType.GetProperty("EventBroker");

            ilGenerator.EmitLoadArg(3);
            ilGenerator.Emit(OpCodes.Callvirt, eventBrokerProperty.GetGetMethod());
            ilGenerator.EmitLoadArg(2);
            ilGenerator.Emit(OpCodes.Callvirt, eventBrokerProperty.PropertyType.GetMethod(Action));
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:10,代码来源:AbstractAddRemoveEventAspectDecoratorWeaver.cs

示例7: Weave

        public override void Weave(ILGenerator ilGenerator)
        {
            FieldBuilder fieldBuilder = TypeDefinition.GetFieldBuilder(ContractType);

            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);

            Method.GetParameters()
                      .Select(p => p.ParameterType)
                      .ForEach(1, (paramType, i) => ilGenerator.EmitLoadArg(i));

            ilGenerator.Emit(OpCodes.Callvirt, Method);
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:13,代码来源:MethodDecoratorScopeWeaver.cs

示例8: WeaveFunction

        protected override void WeaveFunction(ILGenerator ilGenerator)
        {
            var aspectArgumentContract = method.ToAspectArgumentContract();
            var setReturnValueWeaver = new SetReturnValueWeaver(aspectArgumentContract);
            var returnValueGetMethod = aspectArgumentContract.GetProperty("ReturnValue");

            byRefArgumentsStoreWeaver.StoreArgsIfNeeded(ilGenerator);
            ilGenerator.EmitLoadArg(2);
            argumentsWeaver.Weave(ilGenerator);
            ilGenerator.Emit(OpCodes.Callvirt, method);
            setReturnValueWeaver.Weave(ilGenerator);
            byRefArgumentsStoreWeaver.RestoreArgsIfNeeded(ilGenerator);
            ilGenerator.EmitLoadArg(2);
            ilGenerator.Emit(OpCodes.Callvirt, returnValueGetMethod.GetGetMethod());
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:15,代码来源:MethodDecoratorScopeWeaver.cs

示例9: Weave

        public override void Weave(ILGenerator ilGenerator)
        {
            var aspectArgsType = @event.ToEventArgumentContract();
            var eventArgs = Method.GetParameters();

            ilGenerator.EmitLoadArg(2);

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

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

            ilGenerator.Emit(OpCodes.Callvirt, Method);
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:16,代码来源:BindingRaiseEventAspectDecoratorWeaver.cs

示例10: BuildArguments

        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;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:47,代码来源:TopEventInterceptionArgumentsWeaver.cs

示例11: BuildArguments

        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;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:18,代码来源:BindingGetPropertyInterceptionArgumentsWeaver.cs

示例12: Weave

        public override void Weave(ILGenerator ilGenerator)
        {
            var propertyArgumentContract = property.ToPropertyArgumentContract();
            var propertyArgumentContractProperty = propertyArgumentContract.GetProperty("Value");

            argumentsWeaver.Weave(ilGenerator);
            weaver.Weave(ilGenerator);
            ilGenerator.EmitLoadArg(2);
            ilGenerator.Emit(OpCodes.Callvirt, propertyArgumentContractProperty.GetGetMethod());
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:10,代码来源:BindingGetPropertyInterceptionAspectWeaver.cs

示例13: RestoreArgsIfNeeded

        public override void RestoreArgsIfNeeded(ILGenerator ilGenerator)
        {
            byRefParamslocalBuilderMap.ForEach(argPosition => {
                var property = previousAspectArgType.GetProperty("Arg{0}".Fmt(argPosition));

                ilGenerator.EmitLoadLocal(argsLocalBuilder);
                ilGenerator.EmitLoadArg(argPosition);
                ilGenerator.Emit(OpCodes.Ldind_I4);
                ilGenerator.Emit(OpCodes.Callvirt, property.GetSetMethod());
            });
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:11,代码来源:TopAspectByRefArgumentsStoreWeaver.cs

示例14: Weave

        public void Weave(ILGenerator ilGenerator)
        {
            var methodImplParameters = method.GetParameters();
            var aspectArgsType = method.ToAspectArgumentContract();

            ilGenerator.EmitLoadArg(1);
            ilGenerator.Emit(OpCodes.Ldind_Ref);

            methodImplParameters.ForEach(param => {
                var argPosition = param.Position + 1;

                if (byRefArgumentsStoreWeaver.Contains(argPosition)) {
                    byRefArgumentsStoreWeaver.EmitLoadLocalAddress(ilGenerator, argPosition);
                }
                else {
                    var property = aspectArgsType.GetProperty("Arg{0}".Fmt(argPosition));

                    ilGenerator.EmitLoadArg(2);
                    ilGenerator.Emit(OpCodes.Callvirt, property.GetGetMethod());
                }
            });
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:22,代码来源:MethodDecoratorArgumentsWeaver.cs

示例15: Weave

        public void Weave(ILGenerator ilGenerator)
        {
            var typeofType = typeof(Type);
            var typeofObject = typeof(object);
            FieldBuilder contractFieldBuilder = null;
            LocalBuilder typesArrayLocalBuilder = null;
            LocalBuilder tempTypesArrayLocalBuilder = null;
            var typeofArrayOfTypes = typeofType.MakeArrayType();
            var weavingSettings = aspectWeavingSettings.WeavingSettings;
            var getTypeFromHandleMethodInfo = typeofType.GetMethod("GetTypeFromHandle");
            var localBuilderRepository = aspectWeavingSettings.LocalBuilderRepository;

            typesArrayLocalBuilder = localBuilderRepository.Declare(() => {
                return ilGenerator.DeclareLocal(typeofArrayOfTypes);
            });

            tempTypesArrayLocalBuilder = ilGenerator.DeclareLocal(typeofArrayOfTypes);
            ilGenerator.EmitPushInteger(parameters.Length);
            ilGenerator.Emit(OpCodes.Newarr, typeofType);
            ilGenerator.EmitStoreLocal(tempTypesArrayLocalBuilder);

            parameters.ForEach((parameter, i) => {
                var isByRef = parameter.IsByRef;

                if (isByRef) {
                    parameter = parameter.GetElementType();
                }

                ilGenerator.EmitLoadLocal(tempTypesArrayLocalBuilder);
                ilGenerator.EmitPushInteger(i);
                ilGenerator.Emit(OpCodes.Ldtoken, parameter);
                ilGenerator.Emit(OpCodes.Call, getTypeFromHandleMethodInfo);

                if (isByRef) {
                    ilGenerator.Emit(OpCodes.Callvirt, typeofType.GetMethod("MakeByRefType"));
                }

                ilGenerator.Emit(OpCodes.Stelem_Ref);
            });

            ilGenerator.EmitLoadLocal(tempTypesArrayLocalBuilder);
            ilGenerator.EmitStoreLocal(typesArrayLocalBuilder);
            ilGenerator.EmitLoadArg(0);
            contractFieldBuilder = weavingSettings.TypeDefinition.GetFieldBuilder(weavingSettings.ContractType);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.Emit(OpCodes.Callvirt, typeofObject.GetMethod("GetType"));
            ilGenerator.Emit(OpCodes.Ldstr, method.Name);
            ilGenerator.EmitLoadLocal(typesArrayLocalBuilder);
            ilGenerator.Emit(OpCodes.Callvirt, typeofType.GetMethod("GetMethod", new[] { typeof(string), typeof(Type[]) }));
            ilGenerator.EmitStoreLocal(methodLocalBuilder);
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:51,代码来源:AspectArgsMethodWeaver.cs


注:本文中的System.Reflection.Emit.ILGenerator.EmitLoadArg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。