本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}