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


C# MemberInfo.GetCustomAttributes方法代码示例

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


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

示例1: Create

 public static AttributeMap[] Create(TypeModel model, MemberInfo member, bool inherit)
 {
     #if FEAT_IKVM
     System.Collections.Generic.IList<CustomAttributeData> all = member.__GetCustomAttributes(model.MapType(typeof(Attribute)), inherit);
     AttributeMap[] result = new AttributeMap[all.Count];
     int index = 0;
     foreach (CustomAttributeData attrib in all)
     {
         result[index++] = new AttributeDataMap(attrib);
     }
     return result;
     #else
     #if WINRT
     Attribute[] all = System.Linq.Enumerable.ToArray(member.GetCustomAttributes(inherit));
     #else
     var all = member.GetCustomAttributes(inherit);
     #endif
     var result = new AttributeMap[all.Length];
     for (var i = 0; i < all.Length; i++)
     {
         result[i] = new ReflectionAttributeMap((Attribute) all[i]);
     }
     return result;
     #endif
 }
开发者ID:289997171,项目名称:vicking,代码行数:25,代码来源:AttributeMap.cs

示例2: ConstructArgumentHandler

 private ArgumentHandler ConstructArgumentHandler(MemberInfo info, Argument arg)
 {
     ArgumentHandler ai;
       var memberType = GetMemberType(info);
       var min = 0;
       var max = 0;
       var margs = info.GetCustomAttributes(typeof(MultipleArguments), true) as MultipleArguments[];
       if (margs.Length == 1) {
     min = margs[0].Min;
     max = margs[0].Max;
       }
       if (memberType.IsArray) {
     ai = new ArrayArgumentHandler(this, info, memberType, min, max);
       }
       else if (isIList(memberType)) {
     ai = new IListArgumentHandler(this, info, memberType, min, max);
       }
       else if (memberType == typeof(bool) || memberType == typeof(Boolean) || memberType.IsSubclassOf(typeof(Boolean))) {
     var bargs = info.GetCustomAttributes(typeof(FlagArgument), true) as FlagArgument[];
     ai = new FlagArgumentHandler(this, info, arg.OnCollision, arg.Required, bargs.Length != 0 ? bargs[0].WhenSet : true);
       }
       else if (info.GetCustomAttributes(typeof(CountedArgument), true).Length != 0) {
     ai = new CounterArgumentHandler(this, info, memberType, arg.Required);
       }
       else {
     ai = new PlainArgumentHandler(this, info, memberType, arg.OnCollision, arg.Required);
       }
       return ai;
 }
开发者ID:priestd09,项目名称:getoptnet,代码行数:29,代码来源:GetOpt_Initialize.cs

示例3: TestMember

		public TestMember(TestType uiTestType, MemberInfo memberInfo)
		{
			DeclaringType = uiTestType;
			MemberInfo = memberInfo;

			// handle public overrides that inherit attributes
			uiTestAttributes = memberInfo.GetCustomAttributes<UiTestAttribute>();
			categoryAttributes = memberInfo.GetCustomAttributes<CategoryAttribute>();
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:9,代码来源:TestMember.cs

示例4: Property

		public static IElasticPropertyAttribute Property(MemberInfo info)
		{
			var attributes = info.GetCustomAttributes(typeof(IElasticPropertyAttribute), true);
			if (attributes != null && attributes.Any())
				return ((IElasticPropertyAttribute)attributes.First());

			var ignoreAttrutes = info.GetCustomAttributes(typeof(JsonIgnoreAttribute), true);
			if (ignoreAttrutes != null && ignoreAttrutes.Any())
				return new ElasticPropertyAttribute { OptOut = true };

			return null;
		}
开发者ID:radiosterne,项目名称:elasticsearch-net,代码行数:12,代码来源:PropertyNameResolver.cs

示例5: FillCorrelationAliasAttrs

 private static void FillCorrelationAliasAttrs(MemberInfo memberInfo, Hashtable correlationAliasAttrs, ValidationErrorCollection validationErrors)
 {
     foreach (object obj2 in memberInfo.GetCustomAttributes(typeof(CorrelationAliasAttribute), false))
     {
         CorrelationAliasAttribute attributeFromObject = Helpers.GetAttributeFromObject<CorrelationAliasAttribute>(obj2);
         if (string.IsNullOrEmpty(attributeFromObject.Name) || (attributeFromObject.Name.Trim().Length == 0))
         {
             ValidationError item = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationAttributeInvalid", new object[] { typeof(CorrelationAliasAttribute).Name, "Name", memberInfo.Name }), 0x150);
             item.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name);
             validationErrors.Add(item);
         }
         else if (string.IsNullOrEmpty(attributeFromObject.Path) || (attributeFromObject.Path.Trim().Length == 0))
         {
             ValidationError error2 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationAttributeInvalid", new object[] { typeof(CorrelationAliasAttribute).Name, "Path", memberInfo.Name }), 0x150);
             error2.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name);
             validationErrors.Add(error2);
         }
         else if (correlationAliasAttrs.Contains(attributeFromObject.Name))
         {
             ValidationError error3 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_DuplicateCorrelationAttribute", new object[] { typeof(CorrelationAliasAttribute).Name, attributeFromObject.Name, memberInfo.Name }), 0x151);
             error3.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name);
             validationErrors.Add(error3);
         }
         else
         {
             correlationAliasAttrs.Add(attributeFromObject.Name, attributeFromObject);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:CorrelationSetsValidator.cs

示例6: AddMember

        private static void AddMember(ServiceAssembly assembly, ServiceTypeFieldCollection result, MemberInfo member, Type memberType)
        {
            var attributes = member.GetCustomAttributes(typeof(ProtoMemberAttribute), true);

            if (attributes.Length == 0)
                return;

            Debug.Assert(attributes.Length == 1);

            var attribute = (ProtoMemberAttribute)attributes[0];

            var shouldSerializeMember = member.DeclaringType.GetMethod(
                "ShouldSerialize" + member.Name,
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
            );

            result.Add(new ServiceTypeField(
                assembly,
                ReflectionOptimizer.BuildGetter(member),
                ReflectionOptimizer.BuildSetter(member, true),
                shouldSerializeMember == null ? null : ReflectionOptimizer.BuildShouldSerializeInvoker(shouldSerializeMember),
                attribute.Tag,
                attribute.IsRequired,
                memberType
            ));
        }
开发者ID:gmt-europe,项目名称:ProtoChannel,代码行数:26,代码来源:ServiceType.cs

示例7: CollectFilters

		/// <summary>
		/// Implementors should collect the transformfilter information
		/// and return descriptors instances, or an empty array if none
		/// was found.
		/// </summary>
		/// <param name="memberInfo">The action (MethodInfo)</param>
		/// <returns>
		/// An array of <see cref="TransformFilterDescriptor"/>
		/// </returns>
		public TransformFilterDescriptor[] CollectFilters(MemberInfo memberInfo)
		{
			if (logger.IsDebugEnabled)
			{
				logger.DebugFormat("Collecting filters for {0}", memberInfo.Name);
			}

			object[] attributes = memberInfo.GetCustomAttributes(typeof(ITransformFilterDescriptorBuilder), true);

			ArrayList filters = new ArrayList();

			foreach (ITransformFilterDescriptorBuilder builder in attributes)
			{
				TransformFilterDescriptor[] descs = builder.BuildTransformFilterDescriptors();

				if (logger.IsDebugEnabled)
				{
					foreach (TransformFilterDescriptor desc in descs)
					{
						logger.DebugFormat("Collected filter {0} to execute in order {1}",desc.TransformFilterType, desc.ExecutionOrder);
					}
				}

				filters.AddRange(descs);
			}

			return (TransformFilterDescriptor[])filters.ToArray(typeof(TransformFilterDescriptor));
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:37,代码来源:DefaultTransformFilterDescriptorProvider.cs

示例8: GetAttributesForMember

        /// <summary>
        ///   Get attributes for the member.
        /// </summary>
        /// <param name="memberInfo">
        ///   A <b>MemberInfo</b> value.
        /// </param>
        /// <returns>
        ///   A <b>string</b> value contains the attributs for this member.
        /// </returns>
        public static string GetAttributesForMember(MemberInfo memberInfo)
        {
            // Check parameters.
            if (memberInfo == null)
            {
                throw new ArgumentNullException();
            }

            // Get attributes used for this method.
            Object[] attributes = memberInfo.GetCustomAttributes(false);
            if (attributes.Length < 1)
            {
                return null;
            }
            else if (attributes.Length == 1)
            {
                return " (" + attributes[0].GetType().Name + ")";
            }
            else
            {
                string attNames = " (";
                foreach (object o in attributes)
                {
                    attNames += o.GetType().Name + ",";
                }
                attNames = attNames.Substring(0, attNames.Length - 1);
                attNames += ")";
                return attNames;
            }
        }
开发者ID:powernick,项目名称:CodeLib,代码行数:39,代码来源:Utility.cs

示例9: IsExcluded

        /// <summary>
        /// Returns a value indicating whether the value of the specified field will be excluded from a list.
        /// </summary>
        /// <param name="mi">The field to check.</param>
        /// <returns>
        /// true if the value of the specified field will be excleded from a list; otherwise, false.
        /// </returns>
        /// <exception cref="System.NullReferenceException">
        /// Object reference not set to an instance of an object.
        /// </exception>
        public static bool IsExcluded(MemberInfo mi)
        {
            if (mi == null)
                return false;

            return (mi.GetCustomAttributes(typeof(ExcludeAttribute), false).Length > 0);
        }
开发者ID:NLADP,项目名称:ADF,代码行数:17,代码来源:ExcludeAttribute.cs

示例10: ShouldIgnore

 private bool ShouldIgnore(MemberInfo member)
 {
     var attr = member.GetCustomAttributes(typeof(SerializeIgnoreAttribute), true).SingleOrDefault();
     if (attr != null)
         return (attr as SerializeIgnoreAttribute).IgnoreTypes.Contains(_ignoreType);
     return false;
 }
开发者ID:jonhenning,项目名称:CodeEndeavors-Extensions,代码行数:7,代码来源:SerializeIgnoreContractResolver.cs

示例11: GetMemberName

      private String GetMemberName (MemberInfo memberInfo)
      {
         DirectApiAttribute directApiAttribute =
            memberInfo.GetCustomAttributes(false).OfType<DirectApiAttribute>().FirstOrDefault();

         return directApiAttribute == null ? memberInfo.Name : directApiAttribute.Name;
      }
开发者ID:ericklombardo,项目名称:Nuaguil.Net,代码行数:7,代码来源:DirectApi.cs

示例12: HasAliasAttribute

        private static bool HasAliasAttribute(string alias, MemberInfo member)
        {
            var attributes = member.GetCustomAttributes(true);
            var dataMember = attributes.OfType<DataMemberAttribute>()
                .FirstOrDefault();
            if (dataMember != null && dataMember.Name == alias)
            {
                return true;
            }

            var xmlElement = attributes.OfType<XmlElementAttribute>()
                .FirstOrDefault();
            if (xmlElement != null && xmlElement.ElementName == alias)
            {
                return true;
            }

            var xmlAttribute = attributes.OfType<XmlAttributeAttribute>()
                .FirstOrDefault();
            if (xmlAttribute != null && xmlAttribute.AttributeName == alias)
            {
                return true;
            }
            return false;
        }
开发者ID:calebjenkins,项目名称:Highway.Data,代码行数:25,代码来源:MemberNameResolver.cs

示例13: ClassPropInfo

		/// <summary>
		/// Initializes a new instance of the ClassPropInfo class.
		/// </summary>
		/// <param name="memberInfo">The member to represent.</param>
		private ClassPropInfo(MemberInfo memberInfo)
		{
			Type = memberInfo.ReflectedType;
			Name = memberInfo.Name.ToUpperInvariant();

			// try to look up a field with the name
			FieldInfo = memberInfo as FieldInfo;
			if (FieldInfo != null)
			{
				MemberType = FieldInfo.FieldType;
			}
			else
			{
				// get the property
				PropertyInfo p = memberInfo as PropertyInfo;

				// get the getter and setter
				GetMethodInfo = p.GetGetMethod(true);
				SetMethodInfo = p.GetSetMethod(true);

				MemberType = p.PropertyType;
			}

			// see if there is a column attribute defined on the field
			var attribute = memberInfo.GetCustomAttributes(typeof(ColumnAttribute), true).OfType<ColumnAttribute>().FirstOrDefault();
			ColumnName = (attribute != null) ? attribute.ColumnName.ToUpperInvariant() : Name;
		}
开发者ID:micahasmith,项目名称:Insight.Database,代码行数:31,代码来源:ClassPropInfo.cs

示例14: IsMemberRequired

        internal bool IsMemberRequired(MemberInfo memberInfo)
        {
            bool retVal = false;

            if (memberInfo.GetCustomAttributes(true).Any(q => q is RequiredAttribute))
            {
                retVal = true;
            }
            else if (true)
            {
                PropertyInfo propertyInfo = memberInfo as PropertyInfo;
                FieldInfo fieldInfo = memberInfo as FieldInfo;

                if (propertyInfo != null)
                {
                    if (propertyInfo.PropertyType.IsValueType &&
                    !(propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)))
                    {
                        retVal = true;
                    }
                }
                else if (fieldInfo != null)
                {
                    if (fieldInfo.FieldType.IsValueType &&
                    !(fieldInfo.FieldType.IsGenericType && fieldInfo.FieldType.GetGenericTypeDefinition() == typeof(Nullable<>)))
                    {
                        retVal = true;
                    }
                }
            }

            return retVal;
        }
开发者ID:btungut,项目名称:Cruder.Net,代码行数:33,代码来源:CruderHtmlHelper.cs

示例15: GetDisplayName

		// Nasty hack to work around not referencing DataAnnotations directly. 
		// At some point investigate the DataAnnotations reference issue in more detail and go back to using the code above. 
		static string GetDisplayName(MemberInfo member) {
			var attributes = (from attr in member.GetCustomAttributes(true)
			                  select new {attr, type = attr.GetType()}).ToList();

			string name = null;

#if !WINDOWS_PHONE
			name = (from attr in attributes
			        where attr.type.Name == "DisplayAttribute"
			        let method = attr.type.GetRuntimeMethod("GetName", new Type[0]) 
			        where method != null
			        select method.Invoke(attr.attr, null) as string).FirstOrDefault();
#endif

#if !SILVERLIGHT
			if (string.IsNullOrEmpty(name)) {
				name = (from attr in attributes
				        where attr.type.Name == "DisplayNameAttribute"
				        let property = attr.type.GetRuntimeProperty("DisplayName")
				        where property != null
				        select property.GetValue(attr.attr, null) as string).FirstOrDefault();
			}
#endif

			return name;
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:28,代码来源:ValidatorOptions.cs


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