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


C# FieldInfo.GetCustomAttributes方法代码示例

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


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

示例1: FieldBase

        /// <summary>
        /// Create a field base from a fieldinfo object
        /// Verify the settings against the actual field to ensure it will work.
        /// </summary>
        /// <param name="fi">Field Info Object</param>
        internal FieldBase(FieldInfo fi)
        {
            IsNullableType = false;
            TrimMode = TrimMode.None;
            FieldOrder = null;
            InNewLine = false;
            NextIsOptional = false;
            IsOptional = false;
            TrimChars = null;
            NullValue = null;
            TrailingArray = false;
            IsLast = false;
            IsFirst = false;
            IsArray = false;
            CharsToDiscard = 0;
            FieldInfo = fi;
            FieldType = FieldInfo.FieldType;

            if (FieldType.IsArray)
                FieldTypeInternal = FieldType.GetElementType();
            else
                FieldTypeInternal = FieldType;

            IsStringField = FieldTypeInternal == typeof(string);

            object[] attribs = fi.GetCustomAttributes(typeof(FieldConverterAttribute), true);

            if (attribs.Length > 0)
            {
                var conv = (FieldConverterAttribute)attribs[0];
                this.Converter = conv.Converter;
                conv.ValidateTypes(FieldInfo);
            }
            else
                this.Converter = ConvertHelpers.GetDefaultConverter(fi.Name, FieldType);

            if (this.Converter != null)
                this.Converter.mDestinationType = FieldTypeInternal;

            attribs = fi.GetCustomAttributes(typeof(FieldNullValueAttribute), true);

            if (attribs.Length > 0)
            {
                NullValue = ((FieldNullValueAttribute)attribs[0]).NullValue;
                //				mNullValueOnWrite = ((FieldNullValueAttribute) attribs[0]).NullValueOnWrite;

                if (NullValue != null)
                {
                    if (!FieldTypeInternal.IsAssignableFrom(NullValue.GetType()))
                        throw new BadUsageException("The NullValue is of type: " + NullValue.GetType().Name +
                                                    " that is not asignable to the field " + FieldInfo.Name + " of type: " +
                                                    FieldTypeInternal.Name);
                }
            }

            IsNullableType = FieldTypeInternal.IsValueType &&
                                    FieldTypeInternal.IsGenericType &&
                                    FieldTypeInternal.GetGenericTypeDefinition() == typeof(Nullable<>);
        }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:64,代码来源:FieldBase.cs

示例2: CheckAttributesCompatibility

 protected static void CheckAttributesCompatibility(FieldInfo attributeContext, HashSet<Type> incompatibleAttributeTypes)
 {
     if (attributeContext.GetCustomAttributes().Any(a => incompatibleAttributeTypes.Contains(a.GetType())))
     {
         throw new ConfigurationException(
             "Incomatible attributes detected: type={0}, field={1}, attributes={2}.",
             attributeContext.DeclaringType.Name,
             attributeContext.Name,
             attributeContext.GetCustomAttributes()
                 .Where(a => a is EcoAttribute)
                 .Select(a => a.GetType().Name)
                 .CommaWhiteSpaceSeparated()
         );
     }
 }
开发者ID:lukyad,项目名称:Eco,代码行数:15,代码来源:EcoAttribute.cs

示例3: MatchesDirection

        public static bool MatchesDirection(FieldInfo fieldInfo, eDirection direction)
        {
            var attributes = fieldInfo.GetCustomAttributes<DirectionAttribute>();

              return attributes != null &&
             attributes.Any(attr => attr.Direction == direction);
        }
开发者ID:usmanatron,项目名称:amBXPeripheralController,代码行数:7,代码来源:DirectionAttribute.cs

示例4: FetchDisplayName

        /// <summary>
        /// Returns the display name of an enum, or the enum name value if the display name is emtpy or null
        /// </summary>
        /// <param name="field">The field to show.</param>
        /// <returns>The firendly name if there is one, or the enum value if not.</returns>
        private static string FetchDisplayName(FieldInfo field)
        {
            string displayName = String.Empty;

            // load the EnumStringAttributes for the object (there should be 1 and only 1)
            object[] attributes;
            attributes = field.GetCustomAttributes(typeof(EnumDisplayNameAttribute), false);
            EnumDisplayNameAttribute attribute = null;

            if (attributes.Length > 0)
            {
                attribute = attributes[0] as EnumDisplayNameAttribute;
            }

            if (attribute != null)
            {
                // get the DisplayName property from the attribute
                displayName = attribute.DisplayName;
            }
            else
            {
                // if we couldn't get the EnumStringAttribute (or it wasn't set),
                // then default back to the name of the field
                displayName = field.Name;
            }

            return displayName;
        }
开发者ID:robwisehart,项目名称:LetsPLayWar,代码行数:33,代码来源:EnumUtilities.cs

示例5: EnumValue

 private EnumValue(FieldInfo enumField)
 {
     Type enumType = enumField.DeclaringType;
     DescriptionAttribute descriptionAttrib = (DescriptionAttribute)enumField.GetCustomAttributes(typeof(DescriptionAttribute), true).FirstOrDefault();
     this.Description = (descriptionAttrib == null) ? enumField.Name : descriptionAttrib.Description;
     this.Name = enumField.Name;
     this.Value = Convert.ChangeType(Enum.Parse(enumType, this.Name), enumType);
 }
开发者ID:priestofpsi,项目名称:theDiary-Common-Framework,代码行数:8,代码来源:EnumValue.cs

示例6: GetEnumName

 /// <summary>
 /// Returns an enumerated value used by remote Viddler API methods.
 /// </summary>
 internal static string GetEnumName(FieldInfo field)
 {
   foreach (XmlEnumAttribute attribute in field.GetCustomAttributes(typeof(XmlEnumAttribute), true))
   {
     return attribute.Name;
   }
   return null;
 }
开发者ID:spokanedj,项目名称:Viddler-.NET,代码行数:11,代码来源:ViddlerHelper.cs

示例7: GetGuidAttribute

		static GuidAttribute GetGuidAttribute (FieldInfo fi)
		{
			GuidAttribute [] attributes = fi.GetCustomAttributes (typeof (GuidAttribute), false) as GuidAttribute [];
			if (attributes == null || attributes.Length != 1)
				return new GuidAttribute ();

			return attributes [0];
		}
开发者ID:nobled,项目名称:mono,代码行数:8,代码来源:GuidAttribute.cs

示例8: ShouldSkip

        private bool ShouldSkip(FieldInfo fieldInfo)
        {
            var customAttributes = fieldInfo.GetCustomAttributes(false);
            if (HasIgnoreAttribute(customAttributes))
                return true;

            return false;
        }
开发者ID:ohadho,项目名称:ToStringHelper,代码行数:8,代码来源:Printer.cs

示例9: FieldBase

        internal FieldBase(FieldInfo fi)
        {
            mFieldInfo = fi;
            mFieldType = mFieldInfo.FieldType;

            if (mFieldType.IsArray)
                mFieldTypeInternal = mFieldType.GetElementType();
            else
                mFieldTypeInternal = mFieldType;

            mIsStringField = mFieldTypeInternal == strType;

            object[] attribs = fi.GetCustomAttributes(typeof(FieldConverterAttribute), true);

            if (attribs.Length > 0)
            {
                FieldConverterAttribute conv = (FieldConverterAttribute)attribs[0];
                mConvertProvider = conv.Converter;
                conv.ValidateTypes(mFieldInfo);
            }
            else
                mConvertProvider = ConvertHelpers.GetDefaultConverter(fi.Name, mFieldType);

            if (mConvertProvider != null)
                mConvertProvider.mDestinationType = mFieldTypeInternal;

            attribs = fi.GetCustomAttributes(typeof(FieldNullValueAttribute), true);

            if (attribs.Length > 0)
            {
                mNullValue = ((FieldNullValueAttribute)attribs[0]).NullValue;
                //				mNullValueOnWrite = ((FieldNullValueAttribute) attribs[0]).NullValueOnWrite;

                if (mNullValue != null)
                {
                    if (!mFieldTypeInternal.IsAssignableFrom(mNullValue.GetType()))
                        throw new BadUsageException("The NullValue is of type: " + mNullValue.GetType().Name +
                                                    " that is not asignable to the field " + mFieldInfo.Name + " of type: " +
                                                    mFieldTypeInternal.Name);
                }
            }

            mIsNullableType = mFieldTypeInternal.IsValueType &&
                                    mFieldTypeInternal.IsGenericType &&
                                    mFieldTypeInternal.GetGenericTypeDefinition() == typeof(Nullable<>);
        }
开发者ID:hoffmanc,项目名称:FileHelpers,代码行数:46,代码来源:FieldBase.cs

示例10: GetFieldAttribute

 private FieldAttribute GetFieldAttribute(FieldInfo f)
 {
     var attrs = f.GetCustomAttributes(typeof(FieldAttribute), true);
     if (attrs == null || attrs.Length == 0)
     {
         return new FieldAttribute { Align = 1 };
     }
     return (FieldAttribute) attrs[0]; 
 }
开发者ID:killbug2004,项目名称:reko,代码行数:9,代码来源:StructureReader.cs

示例11: ParameterValue

 public ParameterValue(object instance, FieldInfo field)
 {
     ObjectReference = instance;
     Field = field;
     foreach (object attribute in field.GetCustomAttributes(typeof(ParameterAttribute), true))
         Attribute = attribute as ParameterAttribute;
     ReadAttribute();
     ReadValue();
 }
开发者ID:TristramN,项目名称:SourceAFIS,代码行数:9,代码来源:ParameterValue.cs

示例12: GetFieldTypeFor

 internal String GetFieldTypeFor(FieldInfo fieldInfo)
 {
     foreach (Attribute attribute in fieldInfo.GetCustomAttributes(true))
     {
         FieldAttribute fieldAttribute = (FieldAttribute) attribute;
         return fieldAttribute.Type;
     }
     return null;
 }
开发者ID:tocsleung,项目名称:npanday,代码行数:9,代码来源:FieldInjectorRepository.cs

示例13: FieldPropertyDescriptor

 public FieldPropertyDescriptor(FieldInfo fieldInfo)
     : base(fieldInfo.Name, new Attribute[0])
 {
     this.fieldInfo = fieldInfo;
       object[] customAttributes = fieldInfo.GetCustomAttributes(true);
       Attribute[] attributeArray = new Attribute[customAttributes.Length];
       for (int index = 0; index < attributeArray.Length; ++index)
     attributeArray[index] = (Attribute) customAttributes[index];
       this.AttributeArray = attributeArray;
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:10,代码来源:FieldPropertyDescriptor.cs

示例14: ProcessMember

 private static void ProcessMember(FieldInfo member)
 {
     var attributes = member.GetCustomAttributes(typeof(CompositionFieldAttribute), true);
     foreach (var att in attributes.OfType<CompositionFieldAttribute>())
     {
         WriteEvents(member, att.MappedEvents);
         WriteProperties(member, att.MappedProperties);
         WriteMethods(member, att.MappedMethods);
     }
 }
开发者ID:Tenera,项目名称:CompositionAttribute,代码行数:10,代码来源:Program.cs

示例15: foreach

		/// <summary>
		/// Constrói um mapeamento de um campo de um objeto-entidade
		/// para um parâmetro de banco de dados.
		/// </summary>
		/// <param name="campo">Campo a ser mapeado.</param>
		/// <param name="cmd">Comando do banco de dados.</param>
		/// <returns>Mapeamento de um campo para um parâmetro.</returns>
		public static CampoParâmetroBase [] MapearCampoParâmetro(FieldInfo campo, IDbCommand cmd, string prefixo)
		{
			DbAtributo atributo;
			DbAtributo [] atributos;

			atributos = (DbAtributo []) campo.GetCustomAttributes(typeof(DbAtributo), false);
			atributo  = (DbAtributo) atributos;

			/* Relacionamentos necessitam de um mapeamento
			 * mais complexo, permitindo múltiplos campos
			 * a partir de um único objeto.
			 */
			if (atributo.Relacionamento)
			{
                List<CampoObjetoParâmetro> campos = new List<CampoObjetoParâmetro>();

				foreach (DbRelacionamento relacionamento in campo.GetCustomAttributes(typeof(DbRelacionamento), false))
					campos.Add(new CampoObjetoParâmetro(campo, relacionamento.Campo, relacionamento.Coluna, cmd, prefixo));

				return campos.ToArray();
			}


			/* DbFoto deve ser transformado para vetor de bytes
			 * antes da atribuição no parâmetro.
			 */
			if (campo.FieldType == typeof(DbFoto) || campo.FieldType.IsSubclassOf(typeof(DbFoto)))
				return new CampoParâmetroBase [] { new DbFotoParâmetro(campo, cmd, prefixo) };


			/* DateTime pode ser nulo no banco de dados, caso
			 * no programa seu valor seja DateTime.MinValue ou
			 * DateTime.MaxValue.
			 */
			if (campo.FieldType == typeof(DateTime))
				return new CampoParâmetroBase [] { new DateTimeParâmetro(campo, cmd, prefixo) };

			if (campo.FieldType.IsDefined(typeof(DbConversão), true))
                return new CampoParâmetroBase [] { new CampoParâmetroConvertendo(campo, cmd, prefixo) };

			// Mapeamento padrão.
			return new CampoParâmetroBase [] { new CampoParâmetroSimples(campo, cmd, prefixo) };
		}
开发者ID:andrepontesmelo,项目名称:imjoias,代码行数:50,代码来源:FábricaCampoParâmetro.cs


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