C# PropertyGrid 和 Interface 属性
问题: 当对象具有:
class A
{
public ISomeinterface PropertyName { get; set; }
}
然后将该类的实例分配给 propertyGrid.SelectedObject = new A(); 然后,当尝试编辑 PropertyName 的值时,会显示有关无法创建 ISomeinterface 实例的异常(当然是有道理的),问题是如何在不破坏我的类和接口的情况下解决此问题。
Problem:
when object is having:
class A
{
public ISomeinterface PropertyName { get; set; }
}
and then an instance of that class is assigned to propertyGrid.SelectedObject = new A();
then when trying to edit the value of PropertyName, an exception about fail to make instance of ISomeinterface is shown (make sense of course) the question is how to workaround this without break my class's and interfaces.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,PropertyGrid 无法猜测如何分配该值。因此,隐藏它:
如果需要属性分配,那么您需要为该属性实现 UITypeEditor。
Right, PropertyGrid has no hope of guessing how to assign the value. So, hide it:
If property assignment is a requirement then you'll need to implement a UITypeEditor for the property.