C# 中的 ComponentModel、PropertyGrid 和接口
我有一堆实现不同接口的对象,这些接口的一些属性应该通过 PropertyGrid 显示和编辑,但是如果我指定 DisplayName、Browsable 或 DescriptionAttribute 等内容,它们将不会被实现该接口的类“继承”界面……这是为什么?有什么解决办法吗?
I have a bunch of objects that implement different interfaces, some properties of this interfaces should be showed and edited through a PropertyGrid, but if I specify something like DisplayName, Browsable or DescriptionAttribute, they will not be "inherited" by the class that implements the interface... why is this? and is there any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不。不幸的是,属性在特定类型上实现自身。该接口是与实现该接口的成员不同的类型。
您需要在每个类上指定这些属性。这需要更多工作,但也更灵活(因为这些类可以准确确定如何显示其信息,并根据需要进行自定义)。
No. Unfortunately, attributes implement themselves on a specific type. The interface is a separate type than the member that implements the interface.
You'll need to specify those attributes on each class. It's more work, but it also is more flexible (since those classes can determine exactly how to show their information, and customize as needed).