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


C# PropertyInfo.GetCustomAttribute方法代码示例

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


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

示例1: ComputePropertyVisibility

        private static bool ComputePropertyVisibility(PropertyInfo propertyInfo, bool bypassParam, VisibilityLevel visibilityLevel)
        {
            bool isVisible = false;
            var hiddenAttribute = propertyInfo.GetCustomAttribute(typeof(HiddenWhenAttribute));
            var visibilityByPassAttribute = propertyInfo.GetCustomAttribute(typeof(VisibilityByPassAttribute));

            if (visibilityByPassAttribute == null && hiddenAttribute == null) // no attribute = keep in any case
            {
                isVisible = true;
            }
            else if (visibilityByPassAttribute != null && bypassParam)  // bypass attribute + bypassParam = keep
            {
                isVisible = true;
            }
            else if (hiddenAttribute != null)
            {
                HiddenWhenAttribute hiddenLevels = hiddenAttribute as HiddenWhenAttribute;
                if (hiddenLevels != null)
                {
                    if (!hiddenLevels.Levels.Contains(visibilityLevel))
                        isVisible = true;
                }
            }
            else
            {
                isVisible = false;
            }
            return isVisible;
        }
开发者ID:BlueInt32,项目名称:subset-compute,代码行数:29,代码来源:Program.cs

示例2: TsProperty

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

            var propertyType = memberInfo.PropertyType;
            if (propertyType.IsNullable()) {
                propertyType = propertyType.GetNullableValueType();
            }

            this.GenericArguments = propertyType.IsGenericType ? propertyType.GetGenericArguments().Select(o => new TsType(o)).ToArray() : new TsType[0];

            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);

            // Only fields can be constants.
            this.ConstantValue = null;
        }
开发者ID:spelltwister,项目名称:KnockoutTypeLITE,代码行数:32,代码来源:TsProperty.cs

示例3: Column

        public Column(PropertyInfo prop)
        {
            Setter = prop.ToSetter();

            var rowNumberAttr = prop.GetCustomAttribute<RowNumberAttribute>();
            IsRowNumber = rowNumberAttr != null;

            var columnAttr = prop.GetCustomAttribute<ColumnAttribute>();
            Name = columnAttr == null ? prop.Name : columnAttr.Name;
            AccessName = prop.Name;

            NotAllowedEmpty = prop.GetCustomAttribute<AllowedEmptyAttribute>() == null;

            var indexedAttr = prop.GetCustomAttribute<IndexedColumnAttribute>();
            if (indexedAttr != null)
            {
                IndexedNames = indexedAttr.Indexes.Select(x => Name + x).ToList();
            }

            if (IndexedNames == null) ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
            else
            {
                var type = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                ColumnType = type.GenericTypeArguments[0];
            }
        }
开发者ID:naokirin,项目名称:Buffet,代码行数:26,代码来源:Column.cs

示例4: OptionPropertyValue

 public OptionPropertyValue(PropertyInfo propertyInfo, object owner)
 {
     _propertyInfo = propertyInfo;
     _owner = owner;
     _displayName = _propertyInfo.GetCustomAttribute<DisplayNameAttribute>();
     _description = _propertyInfo.GetCustomAttribute<DescriptionAttribute>();
 }
开发者ID:roycornelissen,项目名称:ServiceInsight,代码行数:7,代码来源:OptionPropertyValue.cs

示例5: BooleanFieldMetadata

 /// <summary>
 /// Initializes a new instance of the <see cref="BooleanFieldMetadata"/> class.
 /// </summary>
 /// <param name="declaringProcess">
 /// The declaring process.
 /// </param>
 /// <param name="editProperty">
 /// The editable root property info.
 /// </param>
 /// <param name="infoProperty">
 /// The info class property info.
 /// </param>
 public BooleanFieldMetadata(IProcessMetadata declaringProcess, PropertyInfo editProperty, PropertyInfo infoProperty)
     : base(declaringProcess, editProperty, infoProperty)
 {
     var isSwitchToggleAttribute = editProperty.GetCustomAttribute<IsSwitchToggleAttribute>(false);
     _isSwitchToggle = isSwitchToggleAttribute != null && true.Equals(isSwitchToggleAttribute.Value);
     _undefinedLabelAttribute = editProperty.GetCustomAttribute<UndefinedLabelAttribute>(false);
     _falseLabelAttribute = editProperty.GetCustomAttribute<FalseLabelAttribute>(false);
     _trueLabelAttribute = editProperty.GetCustomAttribute<TrueLabelAttribute>(false);
     _mainLabelAttribute = editProperty.GetCustomAttribute<MainLabelAttribute>(false);
 }
开发者ID:mparsin,项目名称:Elements,代码行数:22,代码来源:BooleanFieldMetadata.cs

示例6: PropertyProxy

            public PropertyProxy(PropertyInfo pi, object target)
            {
                Name = pi.GetCustomAttribute<DisplayNameAttribute>(false)?.DisplayName ?? pi.Name;
                Description = pi.GetCustomAttribute<DescriptionAttribute>(false)?.Description ?? "";
                Order = pi.GetCustomAttribute<OrderAttribute>(false)?.Order ?? int.MaxValue;
                Visible = pi.GetCustomAttribute<VisibleAttribute>(false)?.Visible ?? true;

                Property = pi;
                Target = target;
                RegisterPropertyChanged();
            }
开发者ID:cedianoost,项目名称:3DS-Theme-Editor,代码行数:11,代码来源:PropertyListConverter.cs

示例7: PropertyMap

        public PropertyMap(PropertyInfo propertyInfo)
        {
            this.PropertyInfo = propertyInfo;
            this.Ignored = propertyInfo.GetCustomAttribute<NotMappedAttribute>() != null;
            this.IsKey = propertyInfo.GetCustomAttribute<KeyAttribute>() != null;

            var columnAttribute = propertyInfo.GetCustomAttribute<ColumnAttribute>();
            this.ColumnName = columnAttribute?.Name ?? PropertyInfo.Name;

            var databaseGeneratedAttribute = propertyInfo.GetCustomAttribute<DatabaseGeneratedAttribute>();
            this.DatabaseGeneratedOption = databaseGeneratedAttribute?.DatabaseGeneratedOption ?? DatabaseGeneratedOption.None;
        }
开发者ID:vip32,项目名称:cadru,代码行数:12,代码来源:PropertyMap.cs

示例8: CreatePropertyObject

        public static Property CreatePropertyObject(PropertyInfo propInfo, out Dictionary<string, Structure> structures)
        { 
            structures = new Dictionary<string, Structure>();

            Property result = new VSPlugin.Property();

            string itemsType = "";
            Structure structure = null;

            // we need to verify if we have a structure in this property
            StructureAttribute structureAttribute = propInfo.GetCustomAttribute<StructureAttribute>();
            if (structureAttribute != null)
                result.Type = structureAttribute.Type;
            else
                result.Type = Utility.HandleProperty(propInfo, out itemsType, out structure);

            if (!string.IsNullOrEmpty(itemsType))
            {
                result.Items = new ArraySchema();
                result.Items.Type = itemsType;
            }
            if (structure != null)
                structures.Add(propInfo.PropertyType.Name, structure);

            PropertyAttribute propAttrib = propInfo.GetCustomAttribute<PropertyAttribute>();
            if (propAttrib == null)
                return result;

            result.Description = propAttrib.Description;
            result.Required = propAttrib.Required;
            result.Readonly = propAttrib.ReadOnly;
            result.Final = propAttrib.Final;
            result.Encrypted = propAttrib.Encrypted;
            result.Unit = propAttrib.Unit;
            result.Default = propAttrib.Default;
            result.Format = propAttrib.Format;
            result.Pattern = propAttrib.Pattern;
            result.Title = propAttrib.Title;
            result.Headline = propAttrib.Headline;
            result.MinLength = propAttrib.MinLength;
            result.MaxLength = propAttrib.MaxLength;
            result.MinItems = propAttrib.MinItems;
            result.MaxItems = propAttrib.MaxItems;
            result.UniqueItems = propAttrib.UniqueItems;
            result.EnumValues = propAttrib.Enum;
            result.EnumTitles = propAttrib.EnumTitles;

            result.Access = Access.GetAccess(propInfo);

            return result;
        }
开发者ID:lasttry,项目名称:APS.CSharp.VSPlugin,代码行数:51,代码来源:Property.cs

示例9: GetPropertyName

        /// <summary>Gets the name of the property for JSON serialization.</summary>
        /// <param name="property">The property.</param>
        /// <returns>The name.</returns>
        public static string GetPropertyName(PropertyInfo property)
        {
            var jsonPropertyAttribute = property.GetCustomAttribute<JsonPropertyAttribute>();
            if (jsonPropertyAttribute != null && !string.IsNullOrEmpty(jsonPropertyAttribute.PropertyName))
                return jsonPropertyAttribute.PropertyName;

            if (property.DeclaringType.GetTypeInfo().GetCustomAttribute<DataContractAttribute>() != null)
            {
                var dataMemberAttribute = property.GetCustomAttribute<DataMemberAttribute>();
                if (dataMemberAttribute != null && !string.IsNullOrEmpty(dataMemberAttribute.Name))
                    return dataMemberAttribute.Name;
            }

            return property.Name;
        }
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:18,代码来源:JsonPathUtilities.cs

示例10: FromPropertyInfo

        private SchemaInfo FromPropertyInfo(PropertyInfo pi)
        {
            if (!this.IsMapped(pi))
                return null;

            Type propertyType = pi.PropertyType;

            bool nullableTypeDetected = propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == CachedTypes.PureNullableType;

            SchemaInfo schema = new SchemaInfo(pi.Name, nullableTypeDetected ? propertyType.GetGenericArguments()[0] : propertyType);

            //NotMapped gibi bir standart
            KeyAttribute keyAtt = pi.GetCustomAttribute<KeyAttribute>();
            if (null != keyAtt)
                schema.IsKey = true;

            if (nullableTypeDetected)
                schema.IsNullable = true;
            else
            {
                if (propertyType.IsClass)
                    schema.IsNullable = true;
                else if (propertyType.IsValueType)
                    schema.IsNullable = false;
            }

            bool hasSetMethod = pi.GetSetMethod() != null;
            if (!hasSetMethod)
                schema.ReadOnly = true;

            this.SetExtendedSchema(schema, pi);

            return schema;
        }
开发者ID:mehmetgoren,项目名称:AppX.Portable,代码行数:34,代码来源:EntityMetaDataProviders.cs

示例11: NumericFieldMetadata

        /// <summary>
        /// Initializes a new instance of the <see cref="NumericFieldMetadata"/> class.
        /// </summary>
        /// <param name="declaringProcess">
        /// The declaring process.
        /// </param>
        /// <param name="editProperty">
        /// The editable root property info.
        /// </param>
        /// <param name="infoProperty">
        /// The info class property info.
        /// </param>
        public NumericFieldMetadata(IProcessMetadata declaringProcess, PropertyInfo editProperty, PropertyInfo infoProperty)
            : base(declaringProcess, editProperty, infoProperty)
        {
            var fieldTypeAttribute = editProperty.GetCustomAttribute<FieldTypeAttribute>(false);
            if (fieldTypeAttribute == null)
                throw new ArgumentException("FieldType attribute not found.");

            _columnType = fieldTypeAttribute.ColumnType;

            var numericAttribute = editProperty.GetCustomAttribute<NumericAttribute>(false);
            if (numericAttribute != null)
            {
                _numericType = numericAttribute.NumericType;
                _decimalDigits = numericAttribute.NumberOfDigits;
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:28,代码来源:NumericFieldMetadata.cs

示例12: TwoRadioOptionsControl

        /// <summary>
        ///     Requires that the bound property has two options in order to bind properly.
        /// </summary>
        public TwoRadioOptionsControl(PropertyInfo property)
        {
            InitializeComponent();

            // Knowing the property info allows us to dynamically generarte the available options based on the class attributes
            // and bind the results to a specified type

            BoundProperty = property;

            var parameterAttribute = BoundProperty.GetCustomAttribute<ItemConditionParameterAttribute>();

            if (parameterAttribute == null)
                throw new Exception(
                    "Invalid Property Type Passed to TwoRadioOptionsControl. Ensure that the property contains an ItemConditionParameterAttribute with two options present.");

            if (parameterAttribute.Options == null || parameterAttribute.Options.Count() != 2)
                throw new Exception(
                    "Invalid Property Type Passed to TwoRadioOptionsControl. Ensure that the property contains an ItemConditionParameterAttribute with two options present.");

            BoundOptions = parameterAttribute.Options;

            ValueLabel.Text = string.IsNullOrEmpty(parameterAttribute.Name) ? property.Name : parameterAttribute.Name;

            OptionOneRadioButton.Text = parameterAttribute.Options[0].Name;
            OptionTwoRadioButton.Text = parameterAttribute.Options[1].Name;
        }
开发者ID:Lbniese,项目名称:PawsPremium,代码行数:29,代码来源:TwoRadioOptionsControl.cs

示例13: Build

 public static TableFieldInfo Build(string tableName, PropertyInfo pi, IFieldHandlerFactory fieldHandlerFactory)
 {
     var fieldHandler = fieldHandlerFactory.CreateFromType(pi.PropertyType, FieldHandlerOptions.None);
     if (fieldHandler == null) throw new BTDBException(string.Format("FieldHandlerFactory did not build property {0} of type {2} in {1}", pi.Name, tableName, pi.PropertyType.FullName));
     var a = pi.GetCustomAttribute<PersistedNameAttribute>();
     return new TableFieldInfo(a != null ? a.Name : pi.Name, fieldHandler);
 }
开发者ID:Xamarui,项目名称:BTDB,代码行数:7,代码来源:TableFieldInfo.cs

示例14: GetLocalizationInfo

        private static LocalizationInfo GetLocalizationInfo(PropertyInfo prop)
        {
            var attr = prop.GetCustomAttribute<LocalizeAttribute>();
            if(attr == null)
            {
                return null;
            }
            var info = new LocalizationInfo
            {
                ResourceName = attr.ResourceName ?? (prop.DeclaringType.Name + "_" + prop.Name)
            };

            if(info.ResourceType != null)
            {
                info.ResourceType = attr.ResourceType;
            }
            else
            {
                var parent = prop.DeclaringType.GetTypeInfo().GetCustomAttribute<LocalizeAttribute>();
                if(parent == null || parent.ResourceType == null)
                {
                    throw new ArgumentException(String.Format(
                        "The property '{0}' or its parent class '{1}' must define a ResourceType in order to be localized.",
                        prop.Name, prop.DeclaringType.Name));
                }
                info.ResourceType = parent.ResourceType;
            }

            return info;
        }
开发者ID:nemec,项目名称:clipr,代码行数:30,代码来源:AttributeConverter.cs

示例15: GetFieldType

        private static string GetFieldType(PropertyInfo property)
        {
            var dataTypeAttrib = property.GetCustomAttribute<DataTypeAttribute>();

            if (dataTypeAttrib == null)
                return null;

            switch (dataTypeAttrib.DataType)
            {
                case DataType.Date:
                    return "date";
                case DataType.DateTime:
                    return "datetime";
                case DataType.EmailAddress:
                    return "email";
                case DataType.ImageUrl:
                    return "image";
                case DataType.Password:
                    return "password";
                case DataType.Time:
                    return "time";
                case DataType.Upload:
                    return "file";

                default:
                    return typeof(HttpPostedFileBase).IsAssignableFrom(property.PropertyType) ? "file" : "text";
            }
        }
开发者ID:RichieYang,项目名称:NHateoas,代码行数:28,代码来源:ActionFieldsGenerator.cs


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