修改 PropertyGrid 中的 CollectionEditor
我目前有一个包含 Call 的列表,它是基类。如果我想将 Call 的派生类添加到列表中,我知道要执行以下操作。
public class CustomCollectionEditor : System.ComponentModel.Design.CollectionEditor
{
private Type[] types;
public CustomCollectionEditor(Type type)
: base(type)
{
types = new Type[] { typeof(Call), typeof(CappedCall) };
}
protected override Type[] CreateNewItemTypes()
{
return types;
}
}
public class DisplayList
{
public DisplayList() { }
[Editor(typeof(CustomCollectionEditor), typeof(UITypeEditor))]
[DataMember] public List<Call> ListCalls { get; set; }
}
我的问题是,无论如何要移动标记包含列表可以包含的所有可能类型的 Type[] 的位置?我想将以下内容添加到我的 CustomCollectionEditor 类中,但这不起作用。
public CustomCollectionEditor(Type type, List<Type> types_)
: base(type)
{
types = types_.ToArray();
}
如果我能够以某种方式在 DisplayList 类中标记 CustomCollectionEditor 需要了解哪些类,那就太理想了。
I currently have a list containing Call's, which is the base class. If I want to add derived classes of Call to the list, I know to do the following.
public class CustomCollectionEditor : System.ComponentModel.Design.CollectionEditor
{
private Type[] types;
public CustomCollectionEditor(Type type)
: base(type)
{
types = new Type[] { typeof(Call), typeof(CappedCall) };
}
protected override Type[] CreateNewItemTypes()
{
return types;
}
}
public class DisplayList
{
public DisplayList() { }
[Editor(typeof(CustomCollectionEditor), typeof(UITypeEditor))]
[DataMember] public List<Call> ListCalls { get; set; }
}
My questions is there anyway of moving where you mark up the Type[] containing all possible types the list can contain? I thought of adding the following to my CustomCollectionEditor class, but this doesn't work.
public CustomCollectionEditor(Type type, List<Type> types_)
: base(type)
{
types = types_.ToArray();
}
It would be ideal if I could mark up which classes the CustomCollectionEditor needed to be aware of in the DisplayList class somehow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,您可以通过使用反射来获取所有类型。
Sure, you can get all types by using reflection.