當前位置: 首頁>>代碼示例>>C#>>正文


C# Cecil.ParameterDefinition類代碼示例

本文整理匯總了C#中Mono.Cecil.ParameterDefinition的典型用法代碼示例。如果您正苦於以下問題:C# ParameterDefinition類的具體用法?C# ParameterDefinition怎麽用?C# ParameterDefinition使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ParameterDefinition類屬於Mono.Cecil命名空間,在下文中一共展示了ParameterDefinition類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddConstructor

        public void AddConstructor(TypeDefinition adapterType,
           FieldReference targetField)
        {
            var adapterCtor = adapterType.AddDefaultConstructor();
            var adapterParameter = new ParameterDefinition(_targetDependency);
            adapterCtor.Parameters.Add(adapterParameter);

            // HACK: Remove the ret instruction from the default constructor and replace it with
            // the field setter
            var adapterBody = adapterCtor.Body;
            var adapterInstructions = adapterBody.Instructions.Cast<Instruction>().Where(i => i.OpCode != OpCodes.Ret).ToArray();
            adapterBody.Instructions.Clear();

            // Copy the old instructions
            var IL = adapterBody.CilWorker;
            foreach (var instruction in adapterInstructions)
            {
                IL.Append(instruction);
            }

            IL.Emit(OpCodes.Ldarg_0);
            IL.Emit(OpCodes.Ldarg, adapterParameter);
            IL.Emit(OpCodes.Stfld, targetField);
            IL.Emit(OpCodes.Ret);
        }
開發者ID:philiplaureano,項目名稱:Taiji,代碼行數:25,代碼來源:AddAdapterConstructor.cs

示例2: MakeHostInstanceGeneric

        internal static MethodReference MakeHostInstanceGeneric(this MethodReference self,
                                                                params TypeReference[] arguments)
        {
            var genericInstanceType = self.DeclaringType.MakeGenericInstanceType(arguments);
            var reference = new MethodReference(self.Name, self.ReturnType, genericInstanceType)
            {
                HasThis = self.HasThis,
                ExplicitThis = self.ExplicitThis,
                CallingConvention = self.CallingConvention
            };

            foreach (var parameter in self.Parameters)
            {
                // TODO: This won't work with methods that has generic arguments, since the ParameterType needs to be replaced. @asbjornu
                var parameterDefinition = new ParameterDefinition(parameter.Name,
                                                                  parameter.Attributes,
                                                                  parameter.ParameterType);
                reference.Parameters.Add(parameterDefinition);
            }

            foreach (var genericParameter in self.GenericParameters)
                reference.GenericParameters.Add(new GenericParameter(genericParameter.Name, reference));

            return reference;
        }
開發者ID:Pomona,項目名稱:Pomona,代碼行數:25,代碼來源:CecilExtensions.cs

示例3: ArgumentReferenceEmitter

        internal ArgumentReferenceEmitter(IdentifierExpression identifierExpression, ParameterDefinition parameterDefinition, ILGenerator ilGenerator, IOpCodeIndexer instructionsIndexer)
            : base(ilGenerator, instructionsIndexer) {

            _parameterDefinition = parameterDefinition;
            _identifierExpression = identifierExpression;
            Type = parameterDefinition.ParameterType.GetActualType();
        }
開發者ID:sagifogel,項目名稱:NJection.LambdaConverter,代碼行數:7,代碼來源:ArgumentReferenceEmitter.cs

示例4: CreateTestAssembly

        private static AssemblyDefinition CreateTestAssembly(OpCode opCode, bool invert)
        {
            var name = new AssemblyNameDefinition("TestConditionalsBoundaryTurtle", new Version(1, 0));
            var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
            var type = new TypeDefinition("TestConditionalsBoundaryTurtle", "TestClass",
                               TypeAttributes.Class | TypeAttributes.Public);
            var intType = assembly.MainModule.Import(typeof(int));
            var boolType = assembly.MainModule.Import(typeof(bool));
            var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
            var param = new ParameterDefinition("input", ParameterAttributes.In, intType);
            method.Parameters.Add(param);
            var resultVariable = new VariableDefinition(boolType);
            method.Body.Variables.Add(resultVariable);

            var processor = method.Body.GetILProcessor();
            Instruction loadReturnValueInstruction = processor.Create(OpCodes.Ldloc, resultVariable);
            method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, param));
            method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
            method.Body.Instructions.Add(processor.Create(opCode));
            if (invert)
            {
                method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
                method.Body.Instructions.Add(processor.Create(OpCodes.Ceq));
            }
            method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
            method.Body.Instructions.Add(loadReturnValueInstruction);
            method.Body.Instructions.Add(processor.Create(OpCodes.Ret));

            type.Methods.Add(method);
            assembly.MainModule.Types.Add(type);
            return assembly;
        }
開發者ID:dbremner,項目名稱:ninjaturtles,代碼行數:32,代碼來源:ConditionalBoundaryTurtleTests.cs

示例5: InjectInterceptedMethod

    MethodDefinition InjectInterceptedMethod(TypeDefinition targetType, MethodDefinition innerOnPropertyChanging)
    {
        var delegateHolderInjector = new DelegateHolderInjector
                                     {
                                         TargetTypeDefinition=targetType,
                                         OnPropertyChangingMethodReference = innerOnPropertyChanging,
                                         ModuleWeaver = this
                                     };
        delegateHolderInjector.InjectDelegateHolder();
        var method = new MethodDefinition(EventInvokerNames.First(), GetMethodAttributes(targetType), ModuleDefinition.TypeSystem.Void);

        var propertyName = new ParameterDefinition("propertyName", ParameterAttributes.None, ModuleDefinition.TypeSystem.String);
        method.Parameters.Add(propertyName);
        if (InterceptorType == InvokerTypes.Before)
        {
            var before = new ParameterDefinition("before", ParameterAttributes.None, ModuleDefinition.TypeSystem.Object);
            method.Parameters.Add(before);
        }

        var action = new VariableDefinition("firePropertyChanging", ActionTypeReference);
        method.Body.Variables.Add(action);

        var variableDefinition = new VariableDefinition("delegateHolder", delegateHolderInjector.TypeDefinition);
        method.Body.Variables.Add(variableDefinition);

        var instructions = method.Body.Instructions;

        var last = Instruction.Create(OpCodes.Ret);
        instructions.Add(Instruction.Create(OpCodes.Newobj, delegateHolderInjector.ConstructorDefinition));
        instructions.Add(Instruction.Create(OpCodes.Stloc_1));
        instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
        instructions.Add(Instruction.Create(OpCodes.Ldarg_1));
        instructions.Add(Instruction.Create(OpCodes.Stfld, delegateHolderInjector.PropertyName));
        instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
        instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
        instructions.Add(Instruction.Create(OpCodes.Stfld, delegateHolderInjector.Target));
        instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
        instructions.Add(Instruction.Create(OpCodes.Ldftn, delegateHolderInjector.MethodDefinition));
        instructions.Add(Instruction.Create(OpCodes.Newobj, ActionConstructorReference));
        instructions.Add(Instruction.Create(OpCodes.Stloc_0));
        instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
        instructions.Add(Instruction.Create(OpCodes.Ldloc_0));
        instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
        instructions.Add(Instruction.Create(OpCodes.Ldfld, delegateHolderInjector.PropertyName));
        if (InterceptorType == InvokerTypes.Before)
        {
            instructions.Add(Instruction.Create(OpCodes.Ldarg_2));
            instructions.Add(Instruction.Create(OpCodes.Call, InterceptMethod));
        }
        else
        {
            instructions.Add(Instruction.Create(OpCodes.Call, InterceptMethod));
        }

        instructions.Add(last);
        method.Body.InitLocals = true;

        targetType.Methods.Add(method);
        return method;
    }
開發者ID:Fody,項目名稱:PropertyChanging,代碼行數:60,代碼來源:MethodInjector.cs

示例6: UseParameter

		private bool UseParameter (MethodDefinition method, ParameterDefinition parameter) 
		{
			foreach (Instruction instruction in method.Body.Instructions) {
				switch (instruction.OpCode.Code) {
					case Code.Ldarg_0:
						if (method.Parameters.IndexOf (parameter) == 0)
							return true;
						break;
					case Code.Ldarg_1:
						if (method.Parameters.IndexOf (parameter) == (method.IsStatic? 1 : 0))
							return true;
						break;
					case Code.Ldarg_2:
						if (method.Parameters.IndexOf (parameter) == (method.IsStatic? 2 : 1))
							return true;
						break;
					case Code.Ldarg_3:
						if (method.Parameters.IndexOf (parameter) == (method.IsStatic? 3 : 2))
							return true;
						break;
					case Code.Ldarg_S:
						if (instruction.Operand.Equals (parameter))
							return true;
						break;
					default:
						break;
				}
			}
			return false;
		}
開發者ID:JianwenSun,項目名稱:mono-soc-2007,代碼行數:30,代碼來源:AvoidUnusedParametersRule.cs

示例7: InjectAsStreamReader

    void InjectAsStreamReader(TypeDefinition targetType, FieldDefinition fieldDefinition)
    {
        AsStreamReaderMethod = new MethodDefinition("AsStreamReader", staticMethodAttributes, StreamReaderTypeReference);
        var streamVariable = new VariableDefinition(StreamTypeReference);
        AsStreamReaderMethod.Body.Variables.Add(streamVariable);
        var pathParam = new ParameterDefinition(ModuleDefinition.TypeSystem.String);
        AsStreamReaderMethod.Parameters.Add(pathParam);
        AsStreamReaderMethod.Body.InitLocals = true;
        var inst = AsStreamReaderMethod.Body.Instructions;

        var skipReturn = Instruction.Create(OpCodes.Nop);

        inst.Add(Instruction.Create(OpCodes.Ldsfld, fieldDefinition));
        inst.Add(Instruction.Create(OpCodes.Ldarg, pathParam));
        inst.Add(Instruction.Create(OpCodes.Callvirt, GetManifestResourceStreamMethod));

        inst.Add(Instruction.Create(OpCodes.Stloc, streamVariable));
        inst.Add(Instruction.Create(OpCodes.Ldloc, streamVariable));
        inst.Add(Instruction.Create(OpCodes.Brtrue_S, skipReturn));

        inst.Add(Instruction.Create(OpCodes.Ldnull));
        inst.Add(Instruction.Create(OpCodes.Ret));
        inst.Add(skipReturn);

        inst.Add(Instruction.Create(OpCodes.Ldloc, streamVariable));
        inst.Add(Instruction.Create(OpCodes.Newobj, StreamReaderConstructorReference));
        inst.Add(Instruction.Create(OpCodes.Ret));
        targetType.Methods.Add(AsStreamReaderMethod);
    }
開發者ID:huoxudong125,項目名稱:Resourcer,代碼行數:29,代碼來源:HelperClassInjector.cs

示例8: DomCecilParameter

		public DomCecilParameter (ParameterDefinition parameterDefinition)
		{
			this.parameterDefinition = parameterDefinition;
			base.Name                = parameterDefinition.Name;
//			base.modifiers           = DomCecilType.GetModifiers (parameterDefinition..Attributes);
			base.ReturnType          = DomCecilMethod.GetReturnType (parameterDefinition.ParameterType);
			
			if (parameterDefinition.ParameterType is Mono.Cecil.ReferenceType) {
				this.ParameterModifiers = (parameterDefinition.Attributes & ParameterAttributes.Out) == ParameterAttributes.Out ? ParameterModifiers.Out : ParameterModifiers.Ref;
			} else {
				this.ParameterModifiers = ParameterModifiers.In;
			}
			if ((parameterDefinition.Attributes & ParameterAttributes.Optional) == ParameterAttributes.Optional) 
				this.ParameterModifiers |= ParameterModifiers.Optional;
			
			if ((parameterDefinition.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault) {
				this.DefaultValue = new System.CodeDom.CodePrimitiveExpression (parameterDefinition.Constant);
			}
			
			if (ReturnType.ArrayDimensions > 0) {
				foreach (CustomAttribute customAttribute in parameterDefinition.CustomAttributes) {
					if (customAttribute.Constructor.DeclaringType.FullName == "System.ParamArrayAttribute") 
						this.ParameterModifiers |= ParameterModifiers.Params;
				}
			}
		}
開發者ID:transformersprimeabcxyz,項目名稱:monodevelop-1,代碼行數:26,代碼來源:DomCecilParameter.cs

示例9: Parameter

        public Parameter(ParameterDefinition parameterDefinition, ComponentCache componentCache) : base(parameterDefinition.ParameterType, componentCache)
        {
            Contract.Requires<ArgumentNullException>(parameterDefinition != null);

            parameter = parameterDefinition;
            cache = componentCache;
        }
開發者ID:artur02,項目名稱:Dependency,代碼行數:7,代碼來源:Parameter.cs

示例10: CreateTestAssembly

        private static AssemblyDefinition CreateTestAssembly()
        {
            var name = new AssemblyNameDefinition("TestBranchConditionTurtle", new Version(1, 0));
            var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
            var type = new TypeDefinition("TestBranchConditionTurtle", "TestClass",
                               TypeAttributes.Class | TypeAttributes.Public);
            var intType = assembly.MainModule.Import(typeof(int));
            var boolType = assembly.MainModule.Import(typeof(bool));
            var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
            var leftParam = new ParameterDefinition("left", ParameterAttributes.In, intType);
            var rightParam = new ParameterDefinition("right", ParameterAttributes.In, intType);
            method.Parameters.Add(leftParam);
            method.Parameters.Add(rightParam);
            var resultVariable = new VariableDefinition(boolType);
            method.Body.Variables.Add(resultVariable);

            var processor = method.Body.GetILProcessor();
            Instruction loadReturnValueInstruction = processor.Create(OpCodes.Ldloc, resultVariable);
            Instruction storeTrueInReturnValueInstruction = processor.Create(OpCodes.Ldc_I4, -1);
            method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, leftParam));
            method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, rightParam));
            method.Body.Instructions.Add(processor.Create(OpCodes.Ceq));
            method.Body.Instructions.Add(processor.Create(OpCodes.Brtrue_S, storeTrueInReturnValueInstruction));
            method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
            method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
            method.Body.Instructions.Add(processor.Create(OpCodes.Br_S, loadReturnValueInstruction));
            method.Body.Instructions.Add(storeTrueInReturnValueInstruction);
            method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
            method.Body.Instructions.Add(loadReturnValueInstruction);
            method.Body.Instructions.Add(processor.Create(OpCodes.Ret));

            type.Methods.Add(method);
            assembly.MainModule.Types.Add(type);
            return assembly;
        }
開發者ID:dbremner,項目名稱:ninjaturtles,代碼行數:35,代碼來源:BranchConditionTurtleTests.cs

示例11: CheckForExistingGuard

    private static bool CheckForExistingGuard(Collection<Instruction> instructions, ParameterDefinition parameter)
    {
        for (var i = 1; i < instructions.Count - 1; i++)
        {
            if (instructions[i].OpCode == OpCodes.Newobj)
            {
                var newObjectMethodRef = instructions[i].Operand as MethodReference;

                if (newObjectMethodRef == null || instructions[i + 1].OpCode != OpCodes.Throw)
                    continue;

                // Checks for throw new ArgumentNullException("x");
                if (newObjectMethodRef.FullName == ReferenceFinder.ArgumentNullExceptionConstructor.FullName &&
                    instructions[i - 1].OpCode == OpCodes.Ldstr &&
                    (string)(instructions[i - 1].Operand) == parameter.Name)
                    return true;

                // Checks for throw new ArgumentNullException("x", "some message");
                if (newObjectMethodRef.FullName == ReferenceFinder.ArgumentNullExceptionWithMessageConstructor.FullName &&
                    i > 1 &&
                    instructions[i - 2].OpCode == OpCodes.Ldstr &&
                    (string)(instructions[i - 2].Operand) == parameter.Name)
                    return true;
            }
        }

        return false;
    }
開發者ID:JakeGinnivan,項目名稱:NullGuard,代碼行數:28,代碼來源:MethodProcessor.cs

示例12: LoadArgumentOntoStack

    public static void LoadArgumentOntoStack(List<Instruction> instructions, ParameterDefinition parameter)
    {
        // Load the argument onto the stack
        instructions.Add(Instruction.Create(OpCodes.Ldarg, parameter));

        var elementType = parameter.ParameterType.GetElementType();

        if (parameter.ParameterType.IsByReference)
        {
            if (elementType.IsGenericParameter)
            {
                // Loads an object reference onto the stack
                instructions.Add(Instruction.Create(OpCodes.Ldobj, elementType));

                // Box the type to an object
                instructions.Add(Instruction.Create(OpCodes.Box, elementType));
            }
            else
            {
                // Loads an object reference onto the stack
                instructions.Add(Instruction.Create(OpCodes.Ldind_Ref));
            }
        }
        else if (elementType.IsGenericParameter)
        {
            // Box the type to an object
            instructions.Add(Instruction.Create(OpCodes.Box, parameter.ParameterType));
        }
    }
開發者ID:dpisanu,項目名稱:NullGuard,代碼行數:29,代碼來源:InstructionPatterns.cs

示例13: CreateTestAssembly

        private static AssemblyDefinition CreateTestAssembly()
        {
            var name = new AssemblyNameDefinition("TestArithmeticOperatorTurtleAdd", new Version(1, 0));
            var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
            var type = new TypeDefinition("TestArithmeticOperatorTurtleAdd", "TestClass",
                               TypeAttributes.Class | TypeAttributes.Public);
            var intType = assembly.MainModule.Import(typeof(int));
            var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
            var leftParam = new ParameterDefinition("left", ParameterAttributes.In, intType);
            var rightParam = new ParameterDefinition("right", ParameterAttributes.In, intType);
            method.Parameters.Add(leftParam);
            method.Parameters.Add(rightParam);
            var resultVariable = new VariableDefinition(intType);
            method.Body.Variables.Add(resultVariable);

            var processor = method.Body.GetILProcessor();
            method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg_1));
            method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg_2));
            method.Body.Instructions.Add(processor.Create(OpCodes.Add));
            method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
            method.Body.Instructions.Add(processor.Create(OpCodes.Ldloc, resultVariable));
            method.Body.Instructions.Add(processor.Create(OpCodes.Ret));

            type.Methods.Add(method);
            assembly.MainModule.Types.Add(type);
            return assembly;
        }
開發者ID:dbremner,項目名稱:ninjaturtles,代碼行數:27,代碼來源:MethodTurtleBaseTests.cs

示例14: ImplementISetThis

            /// <summary>
            /// Implement IAsyncSetThis.
            /// </summary>
            private static void ImplementISetThis(TypeDefinition type, ReachableContext reachableContext)
            {
                var thisField = type.Fields.FirstOrDefault(x => x.Name.StartsWith("<>") && x.Name.EndsWith("__this"));
                if (thisField == null)
                    return;

                // Add interface
                var intfType = type.Module.Import(new TypeReference(InternalConstants.Dot42InternalNamespace, "IAsyncSetThis", type.Module, type.Module.Assembly.Name));
                type.Interfaces.Add(new InterfaceImpl(intfType));

                // Add "SetThis(object)" method
                var method = new MethodDefinition("SetThis", MethodAttributes.Public, type.Module.TypeSystem.Void);
                method.SetReachable(reachableContext);
                type.Methods.Add(method);
                var valueParam = new ParameterDefinition(type.Module.TypeSystem.Object);
                method.Parameters.Add(valueParam);
                method.Body = new MethodBody(method) { InitLocals = true };
                var seq = new ILSequence();
                seq.Emit(OpCodes.Ldarg_0); // this
                seq.Emit(OpCodes.Ldarg, valueParam);
                seq.Emit(OpCodes.Castclass, thisField.FieldType);
                seq.Emit(OpCodes.Stfld, thisField);
                seq.Emit(OpCodes.Ret);
                seq.AppendTo(method.Body);
            }
開發者ID:rfcclub,項目名稱:dot42,代碼行數:28,代碼來源:AsyncStateMachineConverter.cs

示例15: Execute

        public static MethodDefinition Execute(PropertyDefinition property_definition, MethodDefinition notify_method, DependencyMap map)
        {
            log.Trace("\t\t\t\t\tAdding collection notification method for " + property_definition.Name);

            // Create method
            TypeReference return_type = property_definition.Module.Import(typeof (void));
            MethodDefinition collection_notification = new MethodDefinition(property_definition.Name + "CollectionNotification", Mono.Cecil.MethodAttributes.Private | Mono.Cecil.MethodAttributes.HideBySig, return_type);

            // Add parameters
            TypeReference sender_type = property_definition.Module.Import(typeof(object));
            TypeReference args_type = property_definition.Module.Import(typeof(NotifyCollectionChangedEventArgs));

            ParameterDefinition sender = new ParameterDefinition("sender", Mono.Cecil.ParameterAttributes.None, sender_type);
            ParameterDefinition args = new ParameterDefinition("args", Mono.Cecil.ParameterAttributes.None, args_type);

            collection_notification.Parameters.Add(sender);
            collection_notification.Parameters.Add(args);

            // Add notifications for dependent properties
            ILProcessor processor = collection_notification.Body.GetILProcessor();
            foreach (var target in map.GetDependenciesFor(property_definition.Name))
            {
                log.Trace("\t\t\t\t\t\tAdding dependency " + target);
                processor.Emit(OpCodes.Ldarg_0);
                processor.Emit(OpCodes.Ldstr, target);
                processor.Emit(OpCodes.Call, notify_method);
            }
            processor.Emit(OpCodes.Ret);

            // Add method to class
            property_definition.DeclaringType.Methods.Add(collection_notification);
            return collection_notification;
        }
開發者ID:lycilph,項目名稱:Projects,代碼行數:33,代碼來源:AddCollectionNotificationMethodTask.cs


注:本文中的Mono.Cecil.ParameterDefinition類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。