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


C# MethodBuilder.DefineParameter方法代码示例

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


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

示例1: Emit

        public void Emit(CompilerErrorCollection errors, MethodBuilder m)
        {
            //Set the parameters
            //ParameterBuilder[] parms = new ParameterInfo[args.Length];
            for(int i = 0; i < args.Length; i++)
                m.DefineParameter(i + 1, ParameterAttributes.None, args[i].Name);

            ILGenerator gen = m.GetILGenerator();

            //Define the IT variable
            LocalRef it = locals["IT"] as LocalRef;
            DefineLocal(gen, it);

            statements.Process(this, errors, gen);

            statements.Emit(this, gen);

            //Cast the IT variable to our return type and return it
            if (m.ReturnType != typeof(void))
            {
                gen.Emit(OpCodes.Ldloc, it.Local);
                Expression.EmitCast(gen, it.Type, m.ReturnType);
            }
            gen.Emit(OpCodes.Ret);
        }
开发者ID:unycorn,项目名称:lolcode-dot-net,代码行数:25,代码来源:Program.cs

示例2: ILDynamicMethodDebugImpl

 public ILDynamicMethodDebugImpl(string name, Type delegateType, Type thisType)
 {
     _delegateType = delegateType;
     _expectedLength = 64;
     var mi = delegateType.GetMethod("Invoke");
     var uniqueName = ILDynamicTypeDebugImpl.UniqueName(name);
     _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(uniqueName), AssemblyBuilderAccess.RunAndSave, DynamicILDirectoryPath.DynamicIL);
     _moduleBuilder = _assemblyBuilder.DefineDynamicModule(uniqueName + ".dll", true);
     var sourceCodeFileName = Path.Combine(DynamicILDirectoryPath.DynamicIL, uniqueName + ".il");
     _symbolDocumentWriter = _moduleBuilder.DefineDocument(sourceCodeFileName, SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft);
     _sourceCodeWriter = new SourceCodeWriter(sourceCodeFileName, _symbolDocumentWriter);
     Type[] parameterTypes;
     if (thisType != null)
     {
         parameterTypes = new[] { thisType }.Concat(mi.GetParameters().Select(pi => pi.ParameterType)).ToArray();
     }
     else
     {
         parameterTypes = mi.GetParameters().Select(pi => pi.ParameterType).ToArray();
     }
     _sourceCodeWriter.StartMethod(name, mi.ReturnType, parameterTypes, MethodAttributes.Static);
     _typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, typeof(object), Type.EmptyTypes);
     _forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
     _dynamicMethod = _typeBuilder.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Static, mi.ReturnType, parameterTypes);
     for (int i = 0; i < parameterTypes.Length; i++)
     {
         _dynamicMethod.DefineParameter(i + 1, ParameterAttributes.In, string.Format("arg{0}", i));
     }
 }
开发者ID:yonglehou,项目名称:BTDB,代码行数:29,代码来源:ILDynamicMethodDebugImpl.cs

示例3: Compile

 internal void Compile(MethodBuilder m)
 {
     if (Builder == null)
     {
         int ofs = (m.IsStatic ? 0 : 1);
         Builder = m.DefineParameter(this.Index + ofs, this.Attributes, this.Name);
     }
 }
开发者ID:rreynolds-yp,项目名称:csharp-swift-consoleclient,代码行数:8,代码来源:EmittedParameter.cs

示例4: ReturnParameter

		public ReturnParameter (MethodBuilder mb, Location location)
		{
			try {
				builder = mb.DefineParameter (0, ParameterAttributes.None, "");			
			}
			catch (ArgumentOutOfRangeException) {
				RootContext.ToplevelTypes.Compiler.Report.RuntimeMissingSupport (location, "custom attributes on the return type");
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:9,代码来源:parameter.cs

示例5: ReturnParameter

		// TODO: merge method and mb
		public ReturnParameter (MemberCore method, MethodBuilder mb, Location location)
		{
			this.method = method;
			try {
				builder = mb.DefineParameter (0, ParameterAttributes.None, "");			
			}
			catch (ArgumentOutOfRangeException) {
				method.Compiler.Report.RuntimeMissingSupport (location, "custom attributes on the return type");
			}
		}
开发者ID:Ein,项目名称:monodevelop,代码行数:11,代码来源:parameter.cs

示例6: ReturnParameter

		public ReturnParameter (MethodBuilder mb, Location location):
			base (null)
		{
			try {
				builder = mb.DefineParameter (0, ParameterAttributes.None, "");			
			}
			catch (ArgumentOutOfRangeException) {
				Report.RuntimeMissingSupport (location, "custom attributes on the return type");
			}
		}
开发者ID:lewurm,项目名称:benchmarker,代码行数:10,代码来源:parameter.cs

示例7: DefineParameters

        public static void DefineParameters(MethodBuilder method, RppParameterInfo[] rppParams)
        {
            Type[] paramTypes = ParametersTypes(rppParams);
            method.SetParameters(paramTypes);

            int index = 1;
            foreach (var param in rppParams)
            {
                param.Index = index; // In static args should start from 1
                method.DefineParameter(index, ParameterAttributes.None, param.Name);
                index++;
            }
        }
开发者ID:dubik,项目名称:csharprpp,代码行数:13,代码来源:RTypeUtils.cs

示例8: CopyMethodSignature

        /// <summary>
        /// Copies the method signature from one method to another.
        /// This includes generic parameters, constraints and parameters.
        /// </summary>
        /// <param name="sourceMethod">The source method.</param>
        /// <param name="targetMethod">The target method.</param>
        internal static void CopyMethodSignature(MethodInfo sourceMethod, MethodBuilder targetMethod)
        {
            CopyGenericSignature(sourceMethod, targetMethod);

            targetMethod.SetReturnType(sourceMethod.ReturnType);

            // copy the parameters and attributes
            // it seems that we can use the source parameters directly because the target method is derived
            // from the source method
            var parameters = sourceMethod.GetParameters();
            targetMethod.SetParameters(parameters.Select(p => p.ParameterType).ToArray());

            for (int i = 0; i < parameters.Length; i++)
            {
                var parameter = parameters[i];
                targetMethod.DefineParameter(i + 1, parameter.Attributes, parameter.Name);
            }
        }
开发者ID:jamezor,项目名称:EventSourceProxy,代码行数:24,代码来源:ProxyHelper.cs

示例9: Execute

        public void Execute()
        {
            var methodAttributes = MethodAttributes.Public;
            if (isOverride) methodAttributes |= MethodAttributes.Virtual;

            methodBuilder = builderBundle().TypeBuilder.DefineMethod(
                methodName()(),
                methodAttributes,
                returnType()(), parameterTypes());

            int counter = 1;
            foreach (Type type in this.parameterTypes())
            {
                methodBuilder.DefineParameter(counter, ParameterAttributes.None, type.Name + "_" + counter);
                counter++;
            }

            this.MethodBuilder = new MethodBuilderBundle(builderBundle(), methodBuilder)
                                     {TypeBuilder = builderBundle().TypeBuilder};
        }
开发者ID:rexwhitten,项目名称:Siege,代码行数:20,代码来源:AddMethodAction.cs

示例10: DefineMembers

 public override void DefineMembers(DefinitionContext c)
 {
     if (method != null)
         throw new InvalidOperationException();
     if (!c.Types.TryGetValue(returntype,out realreturntype))
     {
         throw new ApplicationException();
     }
     realparametertypes = new Type [parametertypes.Length + 1];
     realparametertypes[0] = typeof(ScriptEnvironment);
     for (int i = 0;i < parametertypes.Length;i++)
     {
         if (!c.Types.TryGetValue(parametertypes[i],out realparametertypes[i + 1]))
         {
             throw new ApplicationException();
         }
     }
     method = c.Module.DefineGlobalMethod(name,MethodAttributes.Static | MethodAttributes.Public,realreturntype,realparametertypes);
     for (int i = 0;i < parameternames.Length;i++)
     {
         method.DefineParameter(i + 1,ParameterAttributes.None,parameternames[i]);
     }
     c.DefineMethod(name,method);
 }
开发者ID:VenoMpie,项目名称:DoomSharp,代码行数:24,代码来源:FunctionDefinition.cs

示例11: RegisterBuilders

 public static void RegisterBuilders(this IReadOnlyList<ParameterStructure> prm, MethodBuilder builder, bool isInstance)
 {
     for (var i = 0; i < prm.Count; ++i)
     {
         var p = prm[i];
         var pb = builder.DefineParameter(i + 1, p.Attributes, p.Name);
         p.RegisterBuilder(pb, isInstance);
     }
 }
开发者ID:B-head,项目名称:Dreit-prototype,代码行数:9,代码来源:TranslateUtility.cs

示例12: ApplyAttributes

		public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index)
		{
			if (mb == null)
				builder = cb.DefineParameter (index, Attributes, Name);
			else
				builder = mb.DefineParameter (index, Attributes, Name);

			if (OptAttributes != null)
				OptAttributes.Emit ();

			if (HasDefaultValue) {
				//
				// Emit constant values for true constants only, the other
				// constant-like expressions will rely on default value expression
				//
				Constant c = default_expr as Constant;
				if (c != null) {
					if (default_expr.Type == TypeManager.decimal_type) {
						builder.SetCustomAttribute (Const.CreateDecimalConstantAttribute (c));
					} else {
						builder.SetConstant (c.GetTypedValue ());
					}
				}
			}

			if (parameter_type == InternalType.Dynamic) {
				PredefinedAttributes.Get.Dynamic.EmitAttribute (builder);
			} else {
				var trans_flags = TypeManager.HasDynamicTypeUsed (parameter_type);
				if (trans_flags != null) {
					var pa = PredefinedAttributes.Get.DynamicTransform;
					if (pa.Constructor != null || pa.ResolveConstructor (Location, ArrayContainer.MakeType (TypeManager.bool_type))) {
						builder.SetCustomAttribute (
							new CustomAttributeBuilder (pa.Constructor, new object [] { trans_flags }));
					}
				}
			}
		}
开发者ID:afaerber,项目名称:mono,代码行数:38,代码来源:parameter.cs

示例13: ApplyMethodParameterAttributes

 /// <summary>
 /// Applies attributes to proxied method's parameters.
 /// </summary>
 /// <param name="methodBuilder">The method builder to use.</param>
 /// <param name="targetMethod">The proxied method.</param>
 /// <see cref="IProxyTypeBuilder.ProxyTargetAttributes"/>
 protected virtual void ApplyMethodParameterAttributes(MethodBuilder methodBuilder, MethodInfo targetMethod)
 {
     foreach (ParameterInfo paramInfo in targetMethod.GetParameters())
     {
         ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(
             (paramInfo.Position + 1), paramInfo.Attributes, paramInfo.Name);
         foreach (object attr in GetMethodParameterAttributes(targetMethod, paramInfo))
         {
             if (attr is CustomAttributeBuilder)
             {
                 parameterBuilder.SetCustomAttribute((CustomAttributeBuilder)attr);
             }
             else if (attr is CustomAttributeData)
             {
                 parameterBuilder.SetCustomAttribute(
                     ReflectionUtils.CreateCustomAttribute((CustomAttributeData)attr));
             }
             else if (attr is Attribute)
             {
                 parameterBuilder.SetCustomAttribute(
                     ReflectionUtils.CreateCustomAttribute((Attribute)attr));
             }
         }
     }
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:31,代码来源:AbstractProxyTypeBuilder.cs

示例14: ApplyMethodReturnTypeAttributes

 /// <summary>
 /// Applies attributes to the proxied method's return type.
 /// </summary>
 /// <param name="methodBuilder">The method builder to use.</param>
 /// <param name="targetMethod">The proxied method.</param>
 /// <see cref="IProxyTypeBuilder.ProxyTargetAttributes"/>
 protected virtual void ApplyMethodReturnTypeAttributes(MethodBuilder methodBuilder, MethodInfo targetMethod)
 {
     ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(0, ParameterAttributes.Retval, null);
     foreach (object attr in GetMethodReturnTypeAttributes(targetMethod))
     {
         if (attr is CustomAttributeBuilder)
         {
             parameterBuilder.SetCustomAttribute((CustomAttributeBuilder)attr);
         }
         else if (attr is CustomAttributeData)
         {
             parameterBuilder.SetCustomAttribute(
                 ReflectionUtils.CreateCustomAttribute((CustomAttributeData)attr));
         }
         else if (attr is Attribute)
         {
             parameterBuilder.SetCustomAttribute(
                 ReflectionUtils.CreateCustomAttribute((Attribute)attr));
         }
     }
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:27,代码来源:AbstractProxyTypeBuilder.cs

示例15: SetCustomAttributes

 protected void SetCustomAttributes(MethodBuilder mb)
 {
     GenInterface.SetCustomAttributes(mb, MethodMeta);
     if (Parms != null)
     {
         for (int i = 0; i < Parms.count(); i++)
         {
             IPersistentMap meta = GenInterface.ExtractAttributes(RT.meta(Parms.nth(i)));
             if (meta != null && meta.count() > 0)
             {
                 ParameterBuilder pb = mb.DefineParameter(i + 1, ParameterAttributes.None, ((Symbol)Parms.nth(i)).Name);
                 GenInterface.SetCustomAttributes(pb, meta);
             }
         }
     }
 }
开发者ID:clojure,项目名称:clojure-clr,代码行数:16,代码来源:ObjMethod.cs


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