[英]Converting List<MyClass> Property into PropertyGrid compatible property entries in c#
我有一个具有许多属性的基类。 其中包括带元数据的扩展属性列表。 这是一个自定义类的List,包含DisplayName,Description,Name,Type和Value属性,以帮助PropertyGrid。
期望的最终结果是PropertyGrid显示我的基类属性与上面列表中的扩展属性合并。 我不希望PropertyGrid将我的列表显示为单个条目,而是将每个扩展属性与我的基类属性合并。 本质上,PropertyGrid认为我的扩展属性列表是对象的第一类属性。
这可能使用Reflection或动态类型描述符吗?
使用自定义TypeConverter应该相当简单。
这样的事情将是一个开始:
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override PropertyDescriptorCollection GetProperties(
ITypeDescriptorContext context, object value, Attribute[] attributes)
{
return base.GetProperties(context, value, attributes).
Concat(TypeDescriptor.GetConverter(typeof(TheBaseType)).
GetProperties(context, value, attributes));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.