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


C# MethodAttributes类代码示例

本文整理汇总了C#中MethodAttributes的典型用法代码示例。如果您正苦于以下问题:C# MethodAttributes类的具体用法?C# MethodAttributes怎么用?C# MethodAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: DefineMethod

        public static MethodBuilder DefineMethod(this TypeBuilder typeBuilder, MethodInfo method, MethodAttributes? attributes = null, ParameterInfo[] parameters = null)
        {
            Type[] parametersTypes = null;
            MethodBuilder methodBuilder = null;

            parameters = parameters ?? method.GetParameters();
            parametersTypes = parameters.ToArray(parameter => parameter.ParameterType);
            attributes = attributes ?? method.Attributes & ~MethodAttributes.Abstract;
            methodBuilder = typeBuilder.DefineMethod(method.Name, attributes.Value, method.ReturnType, parametersTypes);

            parameters.ForEach(1, (parameter, i) => {
                var parameterBuilder = methodBuilder.DefineParameter(i, parameter.Attributes, parameter.Name);

                if (parameter.IsDefined<ParamArrayAttribute>()) {
                    parameterBuilder.SetCustomAttribute<ParamArrayAttribute>();
                }
                else if (parameter.IsOut) {
                    parameterBuilder.SetCustomAttribute<OutAttribute>();
                }
                else if (parameter.IsOptional) {
                    parameterBuilder.SetCustomAttribute<OptionalAttribute>()
                                    .SetConstant(parameter.DefaultValue);
                }
            });

            return methodBuilder;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:27,代码来源:ReflectionUtils.cs

示例2: DefineMethod

 public void DefineMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
 {
     bool defaultReturnTypeAndParameters = returnType == null && parameterTypes == null;
     if (callingConvention == CallingConventions.Standard)
     {
         if (defaultReturnTypeAndParameters)
         {
             // Use DefineMethod(string, MethodAttributes)
             TypeBuilder type1 = Helpers.DynamicType(TypeAttributes.Public);
             MethodBuilder method1 = type1.DefineMethod(name, attributes);
             VerifyMethod(type1, method1, name, attributes, callingConvention, returnType, parameterTypes);
         }
         // Use DefineMethod(string, MethodAttributes, Type, Type[])
         TypeBuilder type2 = Helpers.DynamicType(TypeAttributes.Public);
         MethodBuilder method2 = type2.DefineMethod(name, attributes, returnType, parameterTypes);
         VerifyMethod(type2, method2, name, attributes, callingConvention, returnType, parameterTypes);
     }
     if (defaultReturnTypeAndParameters)
     {
         // Use DefineMethod(string, MethodAttributes, CallingConventions)
         TypeBuilder type3 = Helpers.DynamicType(TypeAttributes.Public);
         MethodBuilder method3 = type3.DefineMethod(name, attributes, callingConvention);
         VerifyMethod(type3, method3, name, attributes, callingConvention, returnType, parameterTypes);
     }
     // Use DefineMethod(string, MethodAttributes, CallingConventions, Type, Type[])
     TypeBuilder type4 = Helpers.DynamicType(TypeAttributes.Public);
     MethodBuilder method4 = type4.DefineMethod(name, attributes, callingConvention, returnType, parameterTypes);
     VerifyMethod(type4, method4, name, attributes, callingConvention, returnType, parameterTypes);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:29,代码来源:TypeBuilderDefineMethod.cs

示例3: PropertyKey

 public PropertyKey( TypeKey typeKey, PropertyDefinition prop )
 {
     this.typeKey = typeKey;
     this.type = prop.PropertyType.FullName;
     this.name = prop.Name;
     this.getterMethodAttributes = prop.GetMethod != null ? prop.GetMethod.Attributes : 0;
 }
开发者ID:chinshou,项目名称:Obfuscar,代码行数:7,代码来源:PropertyKey.cs

示例4: ExecutePosTest

        private object[] ExecutePosTest(
                            CustomAttributeBuilder customAttrBuilder,
                            MethodAttributes getMethodAttr,
                            Type returnType,
                            Type[] paramTypes,
                            BindingFlags bindingAttr)
        {
            TypeBuilder myTypeBuilder = GetTypeBuilder(TypeAttributes.Class | TypeAttributes.Public);

            PropertyBuilder myPropertyBuilder = myTypeBuilder.DefineProperty(DynamicPropertyName,
                                                                             PropertyAttributes.HasDefault,
                                                                             returnType, null);
            myPropertyBuilder.SetCustomAttribute(customAttrBuilder);
            // Define the "get" accessor method for DynamicPropertyName
            MethodBuilder myMethodBuilder = myTypeBuilder.DefineMethod(DynamicMethodName,
                                                                       getMethodAttr, returnType, paramTypes);
            ILGenerator methodILGenerator = myMethodBuilder.GetILGenerator();
            methodILGenerator.Emit(OpCodes.Ldarg_0);
            methodILGenerator.Emit(OpCodes.Ret);

            // Map the 'get' method created above to our PropertyBuilder
            myPropertyBuilder.SetGetMethod(myMethodBuilder);

            Type myType = myTypeBuilder.CreateTypeInfo().AsType();

            PropertyInfo myProperty = myType.GetProperty(DynamicPropertyName, bindingAttr);
            return myProperty.GetCustomAttributes(false).Select(a => (object)a).ToArray();
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:28,代码来源:PropertyBuilderSetCustomAttribute1.cs

示例5: DefineConstructor

        /// <summary>
        /// Defines a constructor.
        /// </summary>
        /// <param name="typeBuilder">The type builder.</param>
        /// <param name="methodAttributes">The method attributes.</param>
        /// <param name="callingConvention">The calling convention.</param>
        /// <param name="parameterTypes">The parameter types.</param>
        /// <param name="parameterNames">The parameter names.</param>
        /// <returns>The constructor builder.</returns>
        public static ConstructorBuilder DefineConstructor(this TypeBuilder typeBuilder,
                                                           MethodAttributes methodAttributes,
                                                           CallingConventions callingConvention,
                                                           Type[] parameterTypes,
                                                           string[] parameterNames)
        {
            if (typeBuilder == null)
                throw new ArgumentNullException("typeBuilder");

            if (parameterTypes == null)
                throw new ArgumentNullException("parameterTypes");

            if (parameterNames == null)
                throw new ArgumentNullException("parameterNames");

            if (parameterTypes.Length != parameterNames.Length)
                throw new ArgumentException(Resources.NumberOfParameterTypesAndNamesMustBeEqual);

            // Define constructor.
            var constructorBuilder = typeBuilder.DefineConstructor(
                methodAttributes,
                callingConvention,
                parameterTypes);

            // Define constructor parameters.
            constructorBuilder.DefineParameters(parameterNames);

            return constructorBuilder;
        }
开发者ID:Kostassoid,项目名称:NProxy,代码行数:38,代码来源:TypeBuilderExtensions.cs

示例6: PosTest1

        public void PosTest1()
        {
            int i = 0;
            MethodAttributes[] attributes = new MethodAttributes[] {
                MethodAttributes.Assembly,
                MethodAttributes.CheckAccessOnOverride,
                MethodAttributes.FamANDAssem,
                MethodAttributes.Family,
                MethodAttributes.FamORAssem,
                MethodAttributes.Final,
                MethodAttributes.HasSecurity,
                MethodAttributes.HideBySig,
                MethodAttributes.MemberAccessMask,
                MethodAttributes.NewSlot,
                MethodAttributes.Private,
                MethodAttributes.PrivateScope,
                MethodAttributes.Public,
                MethodAttributes.RequireSecObject,
                MethodAttributes.ReuseSlot,
                MethodAttributes.RTSpecialName,
                MethodAttributes.SpecialName,
                MethodAttributes.Static,
                MethodAttributes.UnmanagedExport,
                MethodAttributes.Virtual,
                MethodAttributes.VtableLayoutMask
            };

            for (; i < attributes.Length; ++i)
            {
                ILGenerator generator =
                    CreateConstructorBuilder("PosTest1_Type" + i, attributes[i]).GetILGenerator();
                Assert.NotNull(generator);
            }
        }
开发者ID:timbarrass,项目名称:corefx,代码行数:34,代码来源:ConstructorBuilderGetILGenerator1.cs

示例7: CreateFunction

        public ILGenerator CreateFunction(TypeBuilder a_TypeBuilder, string a_Name, MethodAttributes a_MethodAttributes, Type a_ReturnType, Type[] a_Parameters)
        {
            MethodBuilder methodBuilder = a_TypeBuilder.DefineMethod(a_Name, a_MethodAttributes, a_ReturnType, a_Parameters);
            ILGenerator ilGenerator = methodBuilder.GetILGenerator();

            return ilGenerator;
        }
开发者ID:JJoosten,项目名称:HA1_MSIL,代码行数:7,代码来源:CustomAssemblyBuilder.cs

示例8: CreateConstructor

        /// <summary>	
        /// 	타입의 생성자를 생성합니다. 
        /// </summary>
        /// <param name="methodAttributes">	생성자 메서드인 .ctor 의 메서드 특성입니다. </param>
        /// <param name="callingConventions">	메서드의 유효한 호출 규칙입니다. </param>
        /// <param name="parameterCriteriaMetadataInfos">	매개 변수의 표준적인 메타데이터 정보입니다. </param>
        /// <returns>	
        /// 	생성자를 생성할 때 사용하는 <see cref="ConstructorBuilder"/> 객체를 반환합니다. 
        /// </returns>
        public ConstructorBuilder CreateConstructor(MethodAttributes methodAttributes, CallingConventions callingConventions, IEnumerable<ParameterCriteriaMetadataInfo> parameterCriteriaMetadataInfos)
        {
            if (isStaticMethod(methodAttributes))
            {
                methodAttributes = MethodAttributes.Static | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Private | MethodAttributes.HideBySig;
                callingConventions = CallingConventions.Standard;
            }
            else
            {
                callingConventions = CallingConventions.HasThis;
            }

            var constructorBuilder = this.TypeBuilder.DefineConstructor(methodAttributes, callingConventions, parameterCriteriaMetadataInfos.Select( o => o.Type).ToArray());

            int iSeqence = 0;
            foreach (var parameter in parameterCriteriaMetadataInfos)
            {
                iSeqence++;
                constructorBuilder.DefineParameter(iSeqence, parameter.ParameterAttribute, parameter.Name);
            }

            var il = constructorBuilder.GetILGenerator();

            if (isStaticMethod(methodAttributes))	// 정적 생성자는 Object 개체 파생이 아니므로 Object 생성을 하지 않음
            {
                il.Emit(OpCodes.Nop);
            }
            else
            {
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Call, this.TypeBuilder.BaseType.GetConstructors()[0]);
            }

            return constructorBuilder;
        }
开发者ID:powerumc,项目名称:UmcCore,代码行数:44,代码来源:TypeBuilderExtension.cs

示例9: EventKey

 public EventKey( TypeKey typeKey, string type, string name, MethodAttributes addMethodAttributes)
 {
     this.typeKey = typeKey;
     this.type = type;
     this.name = name;
     this.addMethodAttributes = addMethodAttributes;
 }
开发者ID:chinshou,项目名称:Obfuscar,代码行数:7,代码来源:EventKey.cs

示例10: NonTargetedMethodMetadata

 public NonTargetedMethodMetadata(MethodInfo method)
     : base(method)
 {
     _methodAttributes = method.Attributes;
     _methodAttributes &= ~MethodAttributes.Abstract;
     _methodAttributes &= ~MethodAttributes.NewSlot;
 }
开发者ID:bradleyjford,项目名称:inception,代码行数:7,代码来源:NonTargetedMethodMetadata.cs

示例11: AddPropertyGetter

        public static MethodDefinition AddPropertyGetter(
            PropertyDefinition property
            , MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.NewSlot | MethodAttributes.Virtual
            , FieldDefinition backingField = null)
        {
            if (backingField == null)
            {
                // TODO: Try and find existing friendly named backingFields first.
                backingField = AddPropertyBackingField(property);
            }

            var methodName = "get_" + property.Name;
            var getter = new MethodDefinition(methodName, methodAttributes, property.PropertyType)
            {
                IsGetter = true,
                Body = {InitLocals = true},
            };

            getter.Body.Variables.Add(new VariableDefinition(property.PropertyType));

            var returnStart = Instruction.Create(OpCodes.Ldloc_0);
            getter.Body.Instructions.Append(
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Ldfld, backingField),
                Instruction.Create(OpCodes.Stloc_0),
                Instruction.Create(OpCodes.Br_S, returnStart),
                returnStart,
                Instruction.Create(OpCodes.Ret)
                );        
                
            property.GetMethod = getter;
            property.DeclaringType.Methods.Add(getter);
            return getter;
        }
开发者ID:brainoffline,项目名称:Commander.Fody,代码行数:34,代码来源:CommandPropertyInjector.cs

示例12: ConstructorBuilder

 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="typeBuilder">Type builder</param>
 /// <param name="attributes">Attributes for the constructor (public, private, etc.)</param>
 /// <param name="parameters">Parameter types for the constructor</param>
 /// <param name="callingConventions">Calling convention for the constructor</param>
 public ConstructorBuilder(TypeBuilder typeBuilder, MethodAttributes attributes,
                           IEnumerable<Type> parameters, CallingConventions callingConventions)
 {
     if (typeBuilder == null)
         throw new ArgumentNullException("typeBuilder");
     Type = typeBuilder;
     Attributes = attributes;
     Parameters = new List<ParameterBuilder>();
     Parameters.Add(new ParameterBuilder(null, 0));
     if (parameters != null)
     {
         int x = 1;
         foreach (var parameterType in parameters)
         {
             Parameters.Add(new ParameterBuilder(parameterType, x));
             ++x;
         }
     }
     CallingConventions = callingConventions;
     Builder = Type.Builder.DefineConstructor(attributes, callingConventions,
                                              (parameters != null && parameters.Count() > 0)
                                                  ? parameters.ToArray()
                                                  : System.Type.EmptyTypes);
     Generator = Builder.GetILGenerator();
 }
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:32,代码来源:ConstructorBuilder.cs

示例13: CheckSupport

    private void CheckSupport(EventDefinition eventInfo, MethodAttributes methodAttributes)
    {
      EventAttributes eventAttributes = eventInfo.Attributes;

      string warningTemplate = "Event '" + name + "' has unsupported attribute: '{0}'.";

      // in order to reduce output we warn only about important attributes which are not currently
      // supported:

      // EventDefinition properties

      // EventAttributes
      //if ((eventAttributes & EventAttributes.RTSpecialName) != 0) { Logger.Warning(warningTemplate, "RTSpecialName"); }
      //if ((eventAttributes & EventAttributes.SpecialName) != 0) { Logger.Warning(warningTemplate, "SpecialName"); }

      // MethodAttributes
      //if ((methodAttributes & MethodAttributes.CheckAccessOnOverride) != 0) { Logger.Warning(warningTemplate, "CheckAccessOnOverride"); }
      //if ((methodAttributes & MethodAttributes.FamANDAssem) != 0) { Logger.Warning(warningTemplate, "FamANDAssem"); }
      // TODO: support this: if ((methodAttributes & MethodAttributes.HasSecurity) != 0) { Logger.Warning(warningTemplate, "HasSecurity"); }
      //if ((methodAttributes & MethodAttributes.HideBySig) != 0) { Logger.Warning(warningTemplate, "HideBySig"); }
      //if ((methodAttributes & MethodAttributes.NewSlot) != 0) { Logger.Warning(warningTemplate, "NewSlot"); }
      // TODO: support this: if ((methodAttributes & MethodAttributes.PinvokeImpl) != 0) { Logger.Warning(warningTemplate, "PinvokeImpl"); }
      //if ((methodAttributes & MethodAttributes.PrivateScope) != 0) { Logger.Warning(warningTemplate, "PrivateScope"); }
      // TODO: support this: if ((methodAttributes & MethodAttributes.RequireSecObject) != 0) { Logger.Warning(warningTemplate, "RequiresSecObject"); }
      //if ((methodAttributes & MethodAttributes.ReuseSlot) != 0) { Logger.Warning(warningTemplate, "ReuseSlot"); }
      //if ((methodAttributes & MethodAttributes.RTSpecialName) != 0) { Logger.Warning(warningTemplate, "RTSpecialName"); }
      //if ((methodAttributes & MethodAttributes.SpecialName) != 0) { Logger.Warning(warningTemplate, "SpecialName"); }
      // TODO: support this: if ((methodAttributes & MethodAttributes.UnmanagedExport) != 0) { Logger.Warning(warningTemplate, "UnmanagedExport"); }
    }
开发者ID:PrintFleet,项目名称:ImmDoc.NET,代码行数:29,代码来源:MyEventInfo.cs

示例14: FunctionObject

 internal FunctionObject(Type t, string name, string method_name, string[] formal_parameters, JSLocalField[] fields, bool must_save_stack_locals, bool hasArgumentsObject, string text, VsaEngine engine) : base(engine.Globals.globalObject.originalFunction.originalPrototype, name, formal_parameters.Length)
 {
     base.engine = engine;
     this.formal_parameters = formal_parameters;
     this.argumentsSlotNumber = 0;
     this.body = null;
     this.method = TypeReflector.GetTypeReflectorFor(Globals.TypeRefs.ToReferenceContext(t)).GetMethod(method_name, BindingFlags.Public | BindingFlags.Static);
     this.parameterInfos = this.method.GetParameters();
     if (!Microsoft.JScript.CustomAttribute.IsDefined(this.method, typeof(JSFunctionAttribute), false))
     {
         this.isMethod = true;
     }
     else
     {
         JSFunctionAttributeEnum attributeValue = ((JSFunctionAttribute) Microsoft.JScript.CustomAttribute.GetCustomAttributes(this.method, typeof(JSFunctionAttribute), false)[0]).attributeValue;
         this.isExpandoMethod = (attributeValue & JSFunctionAttributeEnum.IsExpandoMethod) != JSFunctionAttributeEnum.None;
     }
     this.funcContext = null;
     this.own_scope = null;
     this.fields = fields;
     this.must_save_stack_locals = must_save_stack_locals;
     this.hasArgumentsObject = hasArgumentsObject;
     this.text = text;
     this.attributes = MethodAttributes.Public;
     this.globals = engine.Globals;
     this.superConstructor = null;
     this.superConstructorCall = null;
     this.enclosing_scope = this.globals.ScopeStack.Peek();
     base.noExpando = false;
     this.clsCompliance = CLSComplianceSpec.NotAttributed;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:31,代码来源:FunctionObject.cs

示例15: DefineConstructor

        public void DefineConstructor(MethodAttributes methodAttributes, Type[] parameterTypes, CallingConventions callingConvention, BindingFlags bindingFlags)
        {
            TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);

            FieldBuilder fieldBuilderA = type.DefineField("TestField", typeof(int), FieldAttributes.Private);
            FieldBuilder fieldBuilderB = type.DefineField("TestField", typeof(int), FieldAttributes.Private);

            ConstructorBuilder ctorBuilder = type.DefineConstructor(methodAttributes, callingConvention, parameterTypes);
            ILGenerator ctorIlGenerator = ctorBuilder.GetILGenerator();

            if (parameterTypes.Length != 0)
            {
                //Calling base class constructor
                ctorIlGenerator.Emit(OpCodes.Ldarg_0);
                ctorIlGenerator.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));

                ctorIlGenerator.Emit(OpCodes.Ldarg_0);
                ctorIlGenerator.Emit(OpCodes.Ldarg_1);
                ctorIlGenerator.Emit(OpCodes.Stfld, fieldBuilderA);

                ctorIlGenerator.Emit(OpCodes.Ldarg_0);
                ctorIlGenerator.Emit(OpCodes.Ldarg_2);
                ctorIlGenerator.Emit(OpCodes.Stfld, fieldBuilderB);
            }

            ctorIlGenerator.Emit(OpCodes.Ret);

            Type createdType = type.CreateTypeInfo().AsType();
            Assert.NotNull(createdType.GetConstructors(bindingFlags).FirstOrDefault());
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:30,代码来源:TypeBuilderDefineConstructor.cs


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