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


C# FieldInfo.GetCustomAttribute方法代码示例

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


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

示例1: GetFunction

 public static Functions.Functions GetFunction(FieldInfo field)
 {
     if (field.GetCustomAttribute<OkButtonAttribute>(false) != null)
         return Functions.Functions.Ok;
     if (field.GetCustomAttribute<CloseButtonAttribute>(false) != null)
         return Functions.Functions.Close;
     if (field.GetCustomAttribute<CancelButtonAttribute>(false) != null)
         return Functions.Functions.Cancel;
     return Functions.Functions.None;
 }
开发者ID:yuliapetrova,项目名称:JDITraining,代码行数:10,代码来源:AttributesUtil.cs

示例2: GetAttributesTextFor

        public override IEnumerable<string> GetAttributesTextFor(FieldInfo field, Usage defaultUsage, ParsingPolicyAttribute[] parsingPolicies)
        {
            var res = new List<string>(base.GetAttributesTextFor(field, defaultUsage, parsingPolicies));

            var fieldType = field.FieldType;
            var renameRule = field.GetCustomAttribute<RenameAttribute>();
            string fieldName = field.GetCustomAttribute<NameAttribute>()?.Name ?? field.Name;

            if (!field.IsDefined<RefAttribute>())
            {
                if (field.IsPolymorphic())
                {
                    Type attributeType = !fieldType.IsArray || field.IsDefined<InlineAttribute>() ? typeof(XmlElementAttribute) : typeof(XmlArrayItemAttribute);
                    foreach (var t in field.GetKnownSerializableTypes())
                        res.Add(GetItemAttributeText(attributeType, t, renameRule));
                }
                else if (
                    field.FieldType.IsArray &&
                    !field.IsDefined<ConverterAttribute>() &&
                    !field.IsDefined<ParserAttribute>() &&
                    !parsingPolicies.Any(p => p.CanParse(field.FieldType)))
                {
                    Type attributeType = field.IsDefined<InlineAttribute>() ? typeof(XmlElementAttribute) : typeof(XmlArrayItemAttribute);
                    Type itemTypeName = field.FieldType.GetElementType();
                    res.Add(GetItemAttributeText(attributeType, itemTypeName, renameRule));
                }
            }

            var rawFieldType = field.GetRawFieldType(parsingPolicies);
            if (rawFieldType.IsSimple())
            {
                res.Add(AttributeBuilder.GetTextFor<XmlAttributeAttribute>(fieldName));
            }
            else if (!res.Any(a => a.Contains(nameof(XmlElementAttribute))))
            {
                 if (rawFieldType.IsArray)
                    res.Add(AttributeBuilder.GetTextFor<XmlArrayAttribute>(fieldName));
                 else
                    res.Add(AttributeBuilder.GetTextFor<XmlElementAttribute>(fieldName));
            }

            if (field.IsDefined<HiddenAttribute>())
                res.Add(AttributeBuilder.GetTextFor<XmlIgnoreAttribute>());

            return res.Where(a => a != null);
        }
开发者ID:lukyad,项目名称:Eco,代码行数:46,代码来源:XmlAttributesGenerator.cs

示例3: BuildConfigurationKey

        private string BuildConfigurationKey(FieldInfo constant, string variableName)
        {
            // Can make this polymorphic if the need arises
            if (constant.GetCustomAttribute<StaticKey>() != null)
            {
                return BuildStaticConfigurationKey(variableName);
            }

            return BuildEnvironmentConfigurationKey(variableName);
        }
开发者ID:phillipc47,项目名称:Satellite,代码行数:10,代码来源:ConfigurationKeyData.cs

示例4: Add

        internal void Add(FieldInfo fi)
        {
            if (fi.IsInitOnly)
                return;

            if (fi.IsPrivate)
            { // require DataMemberAttribute
                if (fi.GetCustomAttribute<DataMemberAttribute>() == null)
                    return;
            }

            if (fi.GetCustomAttribute<IgnoreDataMemberAttribute>() != null)
                return;

            var right = makeFieldReader(new FieldFunctionInfo(fi));
            if (right == null)
                return;
            var left = Expression.Field(_pResult, fi);
            _bodyList.Add(Expression.Assign(left, right));
        }
开发者ID:ExM,项目名称:NConfiguration,代码行数:20,代码来源:ComplexFunctionBuilder.cs

示例5: Visit

        public void Visit(string settingsNamespace, string fieldPath, FieldInfo rawSettingsField, object rawSettings)
        {
            var defaultAttr = rawSettingsField.GetCustomAttribute<DefaultAttribute>();
            if (defaultAttr != null)
            {
                if (!CanAssign(rawSettingsField, defaultAttr.Value))
                    throw new ConfigurationException("Invalid default field value for {0}.{1}: '{2}'.", rawSettingsField.DeclaringType.Name, rawSettingsField.Name, defaultAttr.Value);

                object targetValue = rawSettingsField.GetValue(rawSettings);
                if (targetValue == null)
                {
                    if (rawSettingsField.FieldType == typeof(string)) rawSettingsField.SetValue(rawSettings, defaultAttr.Value.ToString());
                    else rawSettingsField.SetValue(rawSettings, defaultAttr.Value);
                }
            }
        }
开发者ID:lukyad,项目名称:Eco,代码行数:16,代码来源:DefaultValueSetter.cs

示例6: ToString

        static string ToString(FieldInfo sourceField, object container)
        {
            object value = sourceField.GetValue(container);
            // Handle nullable types here
            if (value != null && Nullable.GetUnderlyingType(sourceField.FieldType) != null)
            {
                bool hasValue = (bool)sourceField.FieldType.GetProperty("HasValue").GetValue(value);
                if (hasValue) value = sourceField.FieldType.GetProperty("Value").GetValue(value);
            }

            ConverterAttribute converter = sourceField.GetCustomAttribute<ConverterAttribute>();
            if (converter != null)
                return converter.ToString(value, sourceField);
            else
                return value?.ToString();
        }
开发者ID:lukyad,项目名称:Eco,代码行数:16,代码来源:RawSettingsBuilder.cs

示例7: CreateValueDescriptor

        private static ValueDescriptor CreateValueDescriptor(FieldInfo enumValue)
        {
            Debug.Assert(enumValue != null, "enumValue");

            string displayName = null;
            string description = null;

            var displayAttribute = enumValue.GetCustomAttribute<DisplayAttribute>();
            if (displayAttribute != null)
            {
                displayName = displayAttribute.Name;
                description = displayAttribute.Description;
            }

            displayName = displayName ?? enumValue.Name;

            return new ValueDescriptor(displayName, description);
        }
开发者ID:icool123,项目名称:T4Toolbox,代码行数:18,代码来源:KnownValuesAttribute.cs

示例8: TsProperty

        /// <summary>
        /// Initializes a new instance of the TsProperty class with the specific CLR field.
        /// </summary>
        /// <param name="memberInfo">The CLR field represented by this instance of the TsProperty.</param>
        public TsProperty(FieldInfo memberInfo)
        {
            this.MemberInfo = memberInfo;
            this.Name = memberInfo.Name;

            if (memberInfo.ReflectedType.IsGenericType) {
                var definitionType = memberInfo.ReflectedType.GetGenericTypeDefinition();
                var definitionTypeProperty = definitionType.GetProperty(memberInfo.Name);
                if (definitionTypeProperty.PropertyType.IsGenericParameter) {
                    this.PropertyType = TsType.Any;
                } else {
                    this.PropertyType = memberInfo.FieldType.IsEnum ? new TsEnum(memberInfo.FieldType) : new TsType(memberInfo.FieldType);
                }
            } else {
                var propertyType = memberInfo.FieldType;
                if (propertyType.IsNullable()) {
                    propertyType = propertyType.GetNullableValueType();
                }

                this.PropertyType = propertyType.IsEnum ? new TsEnum(propertyType) : new TsType(propertyType);
            }

            var attribute = memberInfo.GetCustomAttribute<TsPropertyAttribute>(false);
            if (attribute != null) {
                if (!string.IsNullOrEmpty(attribute.Name)) {
                    this.Name = attribute.Name;
                }

                this.IsOptional = attribute.IsOptional;
            }

            this.IsIgnored = (memberInfo.GetCustomAttribute<TsIgnoreAttribute>(false) != null);

            if (memberInfo.IsLiteral && !memberInfo.IsInitOnly) {
                // it's a constant
                this.ConstantValue = memberInfo.GetValue(null);
            } else {
                // not a constant
                this.ConstantValue = null;
            }
        }
开发者ID:spelltwister,项目名称:KnockoutTypeLITE,代码行数:45,代码来源:TsProperty.cs

示例9: GetHelpText

 public static void GetHelpText(FieldInfo field, ref string helpText)
 {
     HelpTextAttribute attr = field.GetCustomAttribute<HelpTextAttribute>();
     if(attr != null)
         helpText = attr.HelpText;
 }
开发者ID:TheRealMJP,项目名称:Shadows,代码行数:6,代码来源:Attributes.cs

示例10: GetDisplayName

 public static void GetDisplayName(FieldInfo field, ref string displayName)
 {
     DisplayNameAttribute attr = field.GetCustomAttribute<DisplayNameAttribute>();
     if(attr != null)
         displayName = attr.DisplayName;
 }
开发者ID:TheRealMJP,项目名称:Shadows,代码行数:6,代码来源:Attributes.cs

示例11: HDRColor

 public static bool HDRColor(FieldInfo field)
 {
     HDRAttribute attr = field.GetCustomAttribute<HDRAttribute>();
     if(attr != null)
         return attr.HDR;
     else
         return false;
 }
开发者ID:TheRealMJP,项目名称:Shadows,代码行数:8,代码来源:Attributes.cs

示例12: UseFieldAsShaderConstant

 public static bool UseFieldAsShaderConstant(FieldInfo field)
 {
     UseAsShaderConstantAttribute attr = field.GetCustomAttribute<UseAsShaderConstantAttribute>();
     if(attr != null)
         return attr.UseAsShaderConstant;
     else
         return true;
 }
开发者ID:TheRealMJP,项目名称:Shadows,代码行数:8,代码来源:Attributes.cs

示例13: GetStepSize

 public static void GetStepSize(FieldInfo field, ref int stepSize)
 {
     StepSizeAttribute attr = field.GetCustomAttribute<StepSizeAttribute>();
     if(attr != null)
         stepSize = attr.StepSizeInt;
 }
开发者ID:TheRealMJP,项目名称:Shadows,代码行数:6,代码来源:Attributes.cs

示例14: GetMaxValue

 public static void GetMaxValue(FieldInfo field, ref int maxValue)
 {
     MaxValueAttribute attr = field.GetCustomAttribute<MaxValueAttribute>();
     if(attr != null)
         maxValue = attr.MaxValueInt;
 }
开发者ID:TheRealMJP,项目名称:Shadows,代码行数:6,代码来源:Attributes.cs

示例15: NotUndoableField

    private static bool NotUndoableField(FieldInfo field)
    {
#if NETFX_CORE
      var attr = field.GetCustomAttribute(typeof(NotUndoableAttribute));
      return (attr != null);
#else
      return Attribute.IsDefined(field, typeof(NotUndoableAttribute));
#endif
    }
开发者ID:rachmann,项目名称:csla,代码行数:9,代码来源:UndoableBase.cs


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