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


C# PropertyInfo.GetAttributes方法代码示例

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


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

示例1: Parameter

        public Parameter(PropertyInfo propertyInfo, IHasPositionerCounter context)
        {
            Examples = new List<ExampleAttribute>();

            var attributes = propertyInfo.GetAttributes<DescriptionAttribute>();

            if (attributes.Count == 1)
            {
                Description = attributes[0].Text;
            }

            var argumentAttribute = propertyInfo.GetAttributes<ArgumentAttribute>().Single();

            if (argumentAttribute is NamedArgumentAttribute)
            {
                var namedArgumentAttribute = (NamedArgumentAttribute)argumentAttribute;
                Shorthand = namedArgumentAttribute.ShortHand;
                Name = namedArgumentAttribute.Name;
            }
            else if (argumentAttribute is PositionalArgumentAttribute)
            {
                Position = context.Position++;
            }

            PropertyInfo = propertyInfo;
            ArgumentAttribute = argumentAttribute;

            foreach (var example in propertyInfo.GetAttributes<ExampleAttribute>())
            {
                Examples.Add(example);
            }
        }
开发者ID:rebus-org,项目名称:GoCommando,代码行数:32,代码来源:Parameter.cs

示例2: GetValidationErrors

        private static IEnumerable<IError> GetValidationErrors(object instance, PropertyInfo property)
        {
            var validators = from attribute in property.GetAttributes<ValidationAttribute>(true)
                             where !attribute.IsValid(property.GetValue(instance, null))
                             select new DefaultError(
                                 instance,
                                 property.Name,
                                 attribute.FormatErrorMessage(property.Name)
                                 );

            return validators.OfType<IError>();
        }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:12,代码来源:DefaultValidator.wpf.cs

示例3: GetValidationErrors

        IEnumerable<Error> GetValidationErrors(object instance, PropertyInfo property) {
            var context = new ValidationContext(instance, null, null);
            var validators = from attribute in property.GetAttributes<ValidationAttribute>(true)
                             where attribute.GetValidationResult(property.GetValue(instance, null), context) != ValidationResult.Success
                             select new Error(
                                 instance,
                                 property.Name,
                                 attribute.FormatErrorMessage(property.Name)
                                 );

            return validators.OfType<Error>();
        }
开发者ID:CrazyBBer,项目名称:Caliburn.Micro.Learn,代码行数:12,代码来源:Validator.cs

示例4: PropertyMapper

        /// <summary>
        /// 指定属性元数据,初始化一个 <see cref="PropertyMapper"/> 类的新实例。
        /// </summary>
        /// <param name="typeMapper">类型的映射器。</param>
        /// <param name="property">成员的属性元数据。</param>
        public PropertyMapper(TypeMapper typeMapper, PropertyInfo property)
            : base(property)
        {
            if(typeMapper == null) throw new ArgumentNullException(nameof(typeMapper));
            this.TypeMapper = typeMapper;
            this.IsIgnore = property.GetAttribute<IgnoreAttribute>() != null;
            this._LazyTypeDefaultValue = new Lazy<object>(property.PropertyType.GetDefaultValue);

            var aliasAttr = property.GetAttribute<IAliasAttribute>();
            this.Name = aliasAttr != null && aliasAttr.Name != null
                ? aliasAttr.Name
                : property.Name;

            var keyAttr = property.GetAttribute<IKeyAttribute>();
            this.IsKey = (keyAttr != null && keyAttr.IsKey) || string.Equals(property.Name, DbExtensions.DefaultKeyName, StringComparison.CurrentCultureIgnoreCase);

            this.Validators = property.GetAttributes<IPropertyValidator>().ToArray();
        }
开发者ID:supuy-ruby,项目名称:Aoite,代码行数:23,代码来源:PropertyMapper.cs

示例5: CreateSwaggerModelPropertyData

        private SwaggerModelPropertyData CreateSwaggerModelPropertyData(PropertyInfo pi)
        {
            var modelProperty = new SwaggerModelPropertyData
            {
                Type = pi.PropertyType,
                Name = pi.Name
            };

            foreach (var attr in pi.GetAttributes<SwaggerModelPropertyAttribute>())
            {
                modelProperty.Name = attr.Name ?? modelProperty.Name;
                modelProperty.Description = attr.Description ?? modelProperty.Description;
                modelProperty.Minimum = attr.GetNullableMinimum() ?? modelProperty.Minimum;
                modelProperty.Maximum = attr.GetNullableMaximum() ?? modelProperty.Maximum;
                modelProperty.Required = attr.GetNullableRequired() ?? modelProperty.Required;
                modelProperty.UniqueItems = attr.GetNullableUniqueItems() ?? modelProperty.UniqueItems;
                modelProperty.Enum = attr.Enum ?? modelProperty.Enum;
            }

            return modelProperty;
        }
开发者ID:jchannon,项目名称:Nancy.Swagger,代码行数:21,代码来源:SwaggerAnnotationsConverter.cs

示例6: ShouldValidate

 /// <summary>
 /// Indicates whether the specified property should be validated.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// true if should be validated; otherwise false
 /// </returns>
 public bool ShouldValidate(PropertyInfo property)
 {
     return property.GetAttributes<ValidationAttribute>(true).Any();
 }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:11,代码来源:DefaultValidator.wpf.cs

示例7: GetColumnType

        internal static Type GetColumnType(PropertyInfo prop)
        {
            Type nullableType = Nullable.GetUnderlyingType(prop.PropertyType);
            var type = nullableType ?? prop.PropertyType;

            DataConverterAttribute[] attrs = prop.GetAttributes<DataConverterAttribute>().ToArray();
            if (attrs.Any())
            {
                type = attrs.First().StorageType;
            }
            else if (type.GetTypeInfo().IsEnum)
            {
                var attribute = prop.GetAttributes<EnumAffinityAttribute>().FirstOrDefault();
                type = attribute == null ? typeof (int) : attribute.Type;
            }

            return type;
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:18,代码来源:OrmHelper.cs

示例8: GetPrimaryKey

 internal static PrimaryKeyAttribute GetPrimaryKey(PropertyInfo prop)
 {
     return prop.GetAttributes<PrimaryKeyAttribute>().FirstOrDefault();
 }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:4,代码来源:OrmHelper.cs

示例9: GetIsAutoIncrement

 internal static bool GetIsAutoIncrement(PropertyInfo prop)
 {
     return prop.GetAttributes<AutoIncrementAttribute>().Any();
 }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:4,代码来源:OrmHelper.cs

示例10: GetUnique

 internal static UniqueAttribute GetUnique(PropertyInfo prop)
 {
     return prop.GetAttributes<UniqueAttribute>().FirstOrDefault();
 }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:4,代码来源:OrmHelper.cs

示例11: GetChecks

 internal static string[] GetChecks(PropertyInfo prop)
 {
     return prop.GetAttributes<CheckAttribute>().Select(x => x.Expression).ToArray();
 }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:4,代码来源:OrmHelper.cs

示例12: GetDataConverter

 internal static DataConverterAttribute GetDataConverter(PropertyInfo prop)
 {
     return prop.GetAttributes<DataConverterAttribute>().FirstOrDefault();
 }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:4,代码来源:OrmHelper.cs

示例13: GetIsColumnNullable

        internal static bool GetIsColumnNullable(PropertyInfo prop)
        {
            Type propertyType = prop.PropertyType;
            Type nullableType = Nullable.GetUnderlyingType(propertyType);

            return (nullableType != null || !propertyType.GetTypeInfo().IsValueType) &&
                   !prop.GetAttributes<NotNullAttribute>().Any();
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:8,代码来源:OrmHelper.cs


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