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


C# MethodBuilder.SetCustomAttribute方法代码示例

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


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

示例1: MethodBuilderHelper

		/// <summary>
		/// Initializes a new instance of the <see cref="MethodBuilderHelper"/> class
		/// with the specified parameters.
		/// </summary>
		/// <param name="typeBuilder">Associated <see cref="TypeBuilderHelper"/>.</param>
		/// <param name="methodBuilder">A <see cref="MethodBuilder"/></param>
		public MethodBuilderHelper(TypeBuilderHelper typeBuilder, MethodBuilder methodBuilder)
			: base(typeBuilder)
		{
			if (methodBuilder == null) throw new ArgumentNullException("methodBuilder");

			_methodBuilder = methodBuilder;

			methodBuilder.SetCustomAttribute(Type.Assembly.BLToolkitAttribute);
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:15,代码来源:MethodBuilderHelper.cs

示例2: DefineMembers

 public override void DefineMembers(DefinitionContext c)
 {
     if (method != null)
         throw new InvalidOperationException();
     method = c.GlobalType.DefineMethod("LineSpecial",MethodAttributes.Static | MethodAttributes.Public,typeof(bool),parametertypes);
     foreach (LinedefSpecialAttribute attribute in attributes)
     {
         Type attrtype = typeof(LinedefSpecialAttribute);
         Type[] argtypes = new Type [1];
         argtypes[0] = typeof(int);
         ConstructorInfo ctor = attrtype.GetConstructor(argtypes);
         object[] args = new object [1];
         args[0] = attribute.Number;
         PropertyInfo[] properties = new PropertyInfo [2];
         properties[0] = attrtype.GetProperty("ActivationType");
         properties[1] = attrtype.GetProperty("Repeatable");
         object[] values = new object [2];
         values[0] = attribute.ActivationType;
         values[1] = attribute.Repeatable;
         CustomAttributeBuilder builder = new CustomAttributeBuilder(ctor,args,properties,values);
         method.SetCustomAttribute(builder);
     }
 }
开发者ID:VenoMpie,项目名称:DoomSharp,代码行数:23,代码来源:LinedefSpecialDefinition.cs

示例3: InitializeMethod

        /// <summary>
        /// Initializes a method.
        /// </summary>
        /// <param name="methodBuilder">The current constructor builder.</param>
        /// <param name="methodInfo">The <see cref="MethodInfo"/> associated with the <paramref name="methodBuilder"/>.</param>
        private static void InitializeMethod(MethodBuilder methodBuilder, MethodInfo methodInfo)
        {
            // Apply method attributes
            foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(methodInfo))
            {
                CustomAttributeBuilder cab = CreateCustomAttributeBuilder(cad);
                methodBuilder.SetCustomAttribute(cab);
            }

            // Build parameters
            var parameters = methodInfo.GetParameters();
            for (int i = 0; i < parameters.Length; ++i)
            {
                ParameterInfo parameterInfo = parameters[i];

                string parameterName = string.IsNullOrEmpty(parameterInfo.Name) ?
                    "param" + i.ToString(CultureInfo.InvariantCulture) :
                    parameterInfo.Name;

                ParameterBuilder paramBuilder =
                    methodBuilder.DefineParameter(
                        i + 1, // 1-based index!  (0 == return type)
                        parameterInfo.Attributes,
                        parameterName);

                // Apply parameter attributes
                foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(parameterInfo))
                {
                    CustomAttributeBuilder cab = CreateCustomAttributeBuilder(cad);
                    paramBuilder.SetCustomAttribute(cab);
                }
            }
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:38,代码来源:DomainServiceProxyGenerator.cs

示例4: SetCustomAttributes

 public static void SetCustomAttributes(MethodBuilder mb, IPersistentMap attributes)
 {
     foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes))
         mb.SetCustomAttribute(cab);
 }
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:5,代码来源:GenInterface.cs

示例5: AddDebuggerHiddenAttribute

 private static void AddDebuggerHiddenAttribute(MethodBuilder method)
 {
     var type = typeof(DebuggerHiddenAttribute);
     var customBuilder = new CustomAttributeBuilder(type.GetConstructor(new Type[0]), new object[0]);
     method.SetCustomAttribute(customBuilder);
 }
开发者ID:devIceMan,项目名称:LambdaBuilder,代码行数:6,代码来源:AnonymousTypeBuilder.cs

示例6: MarkMainMethodAsSTA

		void MarkMainMethodAsSTA(MethodBuilder mainMethod)
		{
			mainMethod.SetCustomAttribute(typeof(STAThreadAttribute).GetConstructor(Type.EmptyTypes), new byte[0]);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:4,代码来源:PythonCompiler.cs

示例7: AddIterCreatorName

 public void AddIterCreatorName(MethodBuilder methodBuilder,
                                string name)
 {
     Type[] paramTypes = new Type[] { typeof(string) };
     ConstructorInfo constructor =
         typeof(IterCreatorNameAttribute).GetConstructor(paramTypes);
     CustomAttributeBuilder attrBuilder =
         new CustomAttributeBuilder(constructor,
                                    new object[] { name });
     methodBuilder.SetCustomAttribute(attrBuilder);
     Attribute attr = new IterCreatorNameAttribute(name);
     AddCustomAttribute(methodBuilder, attr);
 }
开发者ID:shugo,项目名称:babel,代码行数:13,代码来源:typemanager.cs

示例8: EmitAttribute

		public void EmitAttribute (MethodBuilder builder)
		{
			if (ResolveBuilder ())
				builder.SetCustomAttribute (cab);
		}
开发者ID:alisci01,项目名称:mono,代码行数:5,代码来源:attribute.cs

示例9: ApplyMethodAttributes

		/// <summary>
		/// Applies attributes to the proxied method.
		/// </summary>
        /// <param name="methodBuilder">The method builder to use.</param>
        /// <param name="targetMethod">The proxied method.</param>
        /// <see cref="IProxyTypeBuilder.ProxyTargetAttributes"/>
        /// <see cref="IProxyTypeBuilder.MemberAttributes"/>
        protected virtual void ApplyMethodAttributes(MethodBuilder methodBuilder, MethodInfo targetMethod)
		{
            foreach (object attr in GetMethodAttributes(targetMethod))
            {
                if (attr is CustomAttributeBuilder)
                {
                    methodBuilder.SetCustomAttribute((CustomAttributeBuilder)attr);
                }
                else if (attr is CustomAttributeData)
                {
                    methodBuilder.SetCustomAttribute(
                        ReflectionUtils.CreateCustomAttribute((CustomAttributeData)attr));
                }
                else if (attr is Attribute)
                {
                    methodBuilder.SetCustomAttribute(
                        ReflectionUtils.CreateCustomAttribute((Attribute)attr));
                }
            }

            ApplyMethodReturnTypeAttributes(methodBuilder, targetMethod);
            ApplyMethodParameterAttributes(methodBuilder, targetMethod);
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:30,代码来源:AbstractProxyTypeBuilder.cs

示例10: CompileOut

        private void CompileOut()
        {
            Out = utilityClass.DefineMethod(Constants.OutMethodName, MethodAttributes.Public | MethodAttributes.Static);

            var genericParameters = declaration.TypeParameters.Any() ? Out.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            var returnType = declaration.TypeParameters.Any()
                ? TypeBuilder.MakeGenericType(genericParameters)
                : TypeBuilder;

            var fGreatestFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, returnType, genericParameters, runtimeContainer);

            Out.SetParameters(fGreatestFixedPoint);

            Out.SetReturnType(returnType);

            Out.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0]));

            var outBody = Out.GetILGenerator();
            outBody.Emit(OpCodes.Ldarg_0);
            outBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any()
                ? TypeBuilder.GetConstructor(
                   InFunction.MakeGenericType(genericParameters),
                   InFunctionConstructor)
                : InFunctionConstructor);
            outBody.Emit(OpCodes.Call, fmap.MakeGenericMethod(new[] { returnType, fGreatestFixedPoint }.Concat(genericParameters).ToArray()));
            outBody.Emit(OpCodes.Call, Ana.MakeGenericMethod(new[] { fGreatestFixedPoint }.Concat(genericParameters).ToArray()));
            outBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:29,代码来源:GFixCompiler.cs

示例11: CompileIn

        private void CompileIn()
        {
            CompileInGeneratingFunction();

            In = utilityClass.DefineMethod(Constants.InMethodName, MethodAttributes.Public | MethodAttributes.Static);

            var genericParameters = declaration.TypeParameters.Any() ? In.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            var resultType = declaration.TypeParameters.Any()
                ? TypeBuilder.MakeGenericType(genericParameters.ToArray())
                : TypeBuilder;

            In.SetReturnType(FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, resultType, genericParameters, runtimeContainer));

            In.SetParameters(resultType);

            In.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0]));

            var fGreatestFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, resultType, genericParameters, runtimeContainer);

            var applyMethodGenericClass = declaration.TypeParameters.Any()
                ? TypeBuilder.GetMethod(
                   TypeBuilder.MakeGenericType(genericParameters),
                   GreatestFixedPointApplyMethod)
                : GreatestFixedPointApplyMethod;
            var applyMethodGenericMethod = applyMethodGenericClass.MakeGenericMethod(fGreatestFixedPoint);

            var inBody = In.GetILGenerator();
            inBody.Emit(OpCodes.Ldarg_0);
            inBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any()
                ? TypeBuilder.GetConstructor(
                   InClass.MakeGenericType(genericParameters),
                   InGeneratingFunctionConstructor)
                : InGeneratingFunctionConstructor);
            inBody.Emit(OpCodes.Callvirt, applyMethodGenericMethod);
            inBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:37,代码来源:GFixCompiler.cs

示例12: AddCompilerGeneratedAttribute

 static void AddCompilerGeneratedAttribute(MethodBuilder getMethodBuilder)
 {
     var compilerGeneratedAttributeCtor = 
         typeof (CompilerGeneratedAttribute).GetConstructor(new Type[0]);
     var compilerGeneratedAttribute = 
         new CustomAttributeBuilder(compilerGeneratedAttributeCtor, new object[0]);    
     getMethodBuilder.SetCustomAttribute(compilerGeneratedAttribute);
 }
开发者ID:osdezwart,项目名称:Page-Type-Builder,代码行数:8,代码来源:ReflectionExtensions.cs

示例13: AddOneWayAttribute

 private void AddOneWayAttribute(MethodBuilder builder) {
     ConstructorInfo info = 
         typeof(System.Runtime.Remoting.Messaging.OneWayAttribute).GetConstructor(Type.EmptyTypes);
     CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(info, new object[0]);
     builder.SetCustomAttribute(attributeBuilder);
 }
开发者ID:JnS-Software-LLC,项目名称:iiop-net,代码行数:6,代码来源:MetadataGenerator.cs

示例14: DefineCustomAttributes

 internal static void DefineCustomAttributes(MethodBuilder member, ReadOnlyCollection<AttributeAst> attributes, Parser parser, AttributeTargets attributeTargets)
 {
     if (attributes != null)
     {
         foreach (var attr in attributes)
         {
             var cabuilder = GetAttributeBuilder(parser, attr, attributeTargets);
             if (cabuilder != null)
             {
                 member.SetCustomAttribute(cabuilder);
             }
         }
     }
 }
开发者ID:40a,项目名称:PowerShell,代码行数:14,代码来源:PSType.cs

示例15: CompileIn

        private void CompileIn()
        {
            In = utilityClass.DefineMethod(Constants.InMethodName, MethodAttributes.Public | MethodAttributes.Static);

            var genericParameters = declaration.TypeParameters.Any() ? In.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            var inputParameter = declaration.TypeParameters.Any() ? TypeBuilder.MakeGenericType(genericParameters.ToArray()) : TypeBuilder;

            In.SetReturnType(FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, inputParameter, genericParameters, runtimeContainer));

            In.SetParameters(inputParameter);

            In.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0]));

            var inBody = In.GetILGenerator();

            var fLeastFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, inputParameter, genericParameters, runtimeContainer);

            inBody.Emit(OpCodes.Ldarg_0);
            inBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any()
                ? TypeBuilder.GetConstructor(
                    OutFunction.MakeGenericType(genericParameters),
                    OutFunctionConstructor)
                : OutFunctionConstructor);
            inBody.Emit(OpCodes.Call, fmap.MakeGenericMethod(new Type[] { fLeastFixedPoint, inputParameter }.Concat(genericParameters).ToArray()));
            inBody.Emit(OpCodes.Callvirt, declaration.TypeParameters.Any()
                ? TypeBuilder.GetMethod(inputParameter, Cata).MakeGenericMethod(fLeastFixedPoint)
                : Cata.MakeGenericMethod(fLeastFixedPoint));
            inBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:30,代码来源:LFixCompiler.cs


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