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


C# PropertyDescriptor.GetAttribute方法代码示例

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


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

示例1: GetDisplayName

        // Copied from DataAnnotationsModelBinder because it was internal and I needed to override OnPropertyValidating above
        protected static string GetDisplayName(PropertyDescriptor descriptor)
        {
            var displayAttribute = descriptor.GetAttribute<DisplayAttribute>();
            if (displayAttribute != null && !String.IsNullOrEmpty(displayAttribute.Name)) {
                return displayAttribute.Name;
            }

            var displayNameAttribute = descriptor.GetAttribute<DisplayNameAttribute>();
            if (displayNameAttribute != null && !String.IsNullOrEmpty(displayNameAttribute.DisplayName)) {
                return displayNameAttribute.DisplayName;
            }

            return descriptor.Name;
        }
开发者ID:fellowshiptech,项目名称:ft-iserve,代码行数:15,代码来源:DotNailsModelBinder.cs

示例2: ConvertValue

        /// <summary>
        /// Converts a data value. Looks for the <see cref="DisplayFormatAttribute"/> to determine
        /// if empty strings should be converted to nulls (true by default).
        /// </summary>
        /// <param name="propertyDescriptor">The property's property descriptor</param>
        /// <param name="value">The original value</param>
        /// <returns>The converted value</returns>
        internal static object ConvertValue(PropertyDescriptor propertyDescriptor,
            object value)
        {
            var displayFormatAttribute = propertyDescriptor.GetAttribute<DisplayFormatAttribute>();
            if ((displayFormatAttribute == null || displayFormatAttribute.ConvertEmptyStringToNull) && Object.Equals(value, String.Empty)) {
                return null;
            }

            return value;
        }
开发者ID:fellowshiptech,项目名称:ft-iserve,代码行数:17,代码来源:DataAnnotationsModelBinder.cs

示例3: Describe

        protected virtual void Describe(PropertyGridProperty property, PropertyDescriptor descriptor)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            if (descriptor == null)
                throw new ArgumentNullException("descriptor");

            property.Descriptor = descriptor;
            property.Name = descriptor.Name;
            property.PropertyType = descriptor.PropertyType;

            // unset by default. conversion service does the default job
            //property.Converter = descriptor.Converter;

            property.Category = string.IsNullOrWhiteSpace(descriptor.Category) || descriptor.Category.EqualsIgnoreCase(CategoryAttribute.Default.Category) ? Grid.DefaultCategoryName : descriptor.Category;
            property.IsReadOnly = descriptor.IsReadOnly;
            property.Description = descriptor.Description;
            property.DisplayName = descriptor.DisplayName;
            if (property.DisplayName == descriptor.Name)
            {
                property.DisplayName = DecamelizationService.Decamelize(property.DisplayName);
            }

            property.IsEnum = descriptor.PropertyType.IsEnum;
            property.IsFlagsEnum = descriptor.PropertyType.IsEnum && Extensions.IsFlagsEnum(descriptor.PropertyType);

            DefaultValueAttribute att = descriptor.GetAttribute<DefaultValueAttribute>();
            property.HasDefaultValue = att != null;
            property.DefaultValue = att != null ? att.Value : null;

            PropertyGridOptionsAttribute options = descriptor.GetAttribute<PropertyGridOptionsAttribute>();
            if (options != null)
            {
                if (options.SortOrder != 0)
                {
                    property.SortOrder = options.SortOrder;
                }

                property.IsEnum = options.IsEnum;
                property.IsFlagsEnum = options.IsFlagsEnum;
            }

            AddDynamicProperties(descriptor.Attributes.OfType<PropertyGridAttribute>(), property.Attributes);
            AddDynamicProperties(descriptor.PropertyType.GetAttributes<PropertyGridAttribute>(), property.TypeAttributes);
        }
开发者ID:modulexcite,项目名称:SoftFluent.Windows,代码行数:46,代码来源:PropertyGridDataProvider.cs

示例4: CreateProperty

        public virtual PropertyGridProperty CreateProperty(PropertyDescriptor descriptor)
        {
            if (descriptor == null)
                throw new ArgumentNullException("descriptor");

            bool forceReadWrite = false;
            PropertyGridProperty property = null;
            PropertyGridOptionsAttribute options = descriptor.GetAttribute<PropertyGridOptionsAttribute>();
            if (options != null)
            {
                forceReadWrite = options.ForceReadWrite;
                if (options.PropertyType != null)
                {
                    property = (PropertyGridProperty)Activator.CreateInstance(options.PropertyType, this);
                }
            }

            if (property == null)
            {
                options = descriptor.PropertyType.GetAttribute<PropertyGridOptionsAttribute>();
                if (options != null)
                {
                    if (!forceReadWrite)
                    {
                        forceReadWrite = options.ForceReadWrite;
                    }
                    if (options.PropertyType != null)
                    {
                        property = (PropertyGridProperty)Activator.CreateInstance(options.PropertyType, this);
                    }
                }
            }

            if (property == null)
            {
                property = CreateProperty();
            }

            Describe(property, descriptor);
            if (forceReadWrite)
            {
                property.IsReadOnly = false;
            }
            property.OnDescribed();
            property.RefreshValueFromDescriptor();
            return property;
        }
开发者ID:modulexcite,项目名称:SoftFluent.Windows,代码行数:47,代码来源:PropertyGridDataProvider.cs


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