我有一堂课:
public class Filter
{
public Filter (string name, string value)
{
Name = name;
Value = value;
}
public string Name {get; private set;}
public string Value {get; set;}
}
还有一个集合类:
public class FilterCollection : Collection<Filter>
{
// code elided
}
我的组件类:
public class MyComponent : Component
{
// ...
[Editor(typeof(FilterEditor), typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public FilterCollection Filters { get; set; }
// ...
}
问题是设计者没有正确序列化集合。
我确定我错过了一些东西,但我不知道是什么。
附加信息
我希望 Designer.cs 文件具有以下内容:
myComponent.Filters.Add (new Filter ("some name", "some value"));
myComponent.Filters.Add (new Filter ("other name", "other value"));
这可行吗?