日期:2014-05-17 浏览次数:21053 次
/// <summary>
/// 设置属性要显示的描述
/// </summary>
/// <param name="obj">属性所属的类</param>
/// <param name="propertyName">属性</param>
/// <param name="value">描述</param>
public static void SetPropertyDescription(ref object obj, string propertyName, string value)
{
Type type = typeof(System.ComponentModel.DescriptionAttribute);
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
AttributeCollection attrs = props[propertyName].Attributes;
FieldInfo fld = type.GetField("description", BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
fld.SetValue(attrs[type], value);
}
/// <summary>
/// 设置属性的分类依据
/// </summary>
/// <param name="obj">属性所属的类</param>
/// <param name="propertyName">属性</param>
/// <param name="value">名称</param>
public static void SetPropertyCategory(object obj, string propertyName, string value)
{
Type type = typeof(System.ComponentModel.CategoryAttribute);