我需要在属性网格中正确显示一个对象。
我的类看起来像这样:
public class PropertyItem
{
public PropertyDescription PropertyDescription { get; set; }
[Description("the value"), Browsable(true)]
public object Value { get; set; }
public PropertyItem(PropertyDescription propertyDescription, object value)
{
PropertyDescription = propertyDescription;
Value = value;
}
public override string ToString()
{
return this.PropertyDescription.Name + ": " + PropertyDescription.Type + ": " + Value;
}
}
Value
是一个 object
类型,不能改变。
PropertyDescription
的类型与 Value
相同,可以是任何类型(如 string
、int
、bool
等)。
当我设置 PropertyGrid
的 SelectedObject
时,Value
总是被禁用。
我该如何编写一个 TypeConverter
来将 object
类型的 Value
转换为 PropertyDescription
中的 Type
?