110,567
社区成员
发帖
与我相关
我的任务
分享
public Form1()
{
InitializeComponent();
this.propertyGrid1.SelectedObject = new My();
}
public class My
{
public My()
{
this.Names = new List<string>() { "hello", "nihao" };
}
[TypeConverter(typeof(MyTypeConverter))] //<---
public List<string> Names { get; private set; }
private class MyTypeConverter : TypeConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value is List<string>)
{
return (value as List<string>).Count + " element(s)";
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}