c# – PropertyGrid.BrowsableAttributes有什么兴趣?

c# – PropertyGrid.BrowsableAttributes有什么兴趣?,第1张

概述NB : This question is tagged C# too as it is a general question and an answer describing the use of this in C# is perfectly fine to me. 我最近在.Net Framework中一直在探索PropertyGrid.我检查了这个属性(BrowsableAttribute

NB : This question is tagged C# too as it is a general question and an
answer describing the use of this in C# is perfectly fine to me.

我最近在.Net Framework中一直在探索PropertyGrID.我检查了这个属性(BrowsableAttributes),我不知道它的使用.

起初我以为这将能够循环遍历Selectedobject中的每个browsableAttribute,然后你就能找回原来的属性,这本来是有用的.

但不,显然所有这个属性都给你一个只包含browsableAttribute的AttributeCollection,都设置为True …

有人可以告诉我这种方法有什么意义吗?我甚至不明白它在.NET中是如何有用的……

Dim attributes = MyPropertyGrID.browsableAttributesFor Each A As Attribute In attributes    Dim browsable As browsableAttribute = CType(A,browsableAttribute)    'Then how can I use this ? it's only property is browsable (True/False)Next

我原本试图解决一个问题,我不知道在属性网格中选择了哪个对象,但我想收集对象的数据.

我不知道对象的类型是什么,因为它来自动态加载的DLL.我只知道它是另一个派生类,我知道.但我很有兴趣备份从Property GrID获得的Object属性,以便以后能够保存和加载它们.

由于属性网格已经包含所有这些值,我认为这种属性可能是编写更多代码的重点.我不想使用反射来检查代码,而Property GrID已经这样做了.

解决方法 BrowsableAttributes财产的工作已在文件中清楚地描述:

Only propertIEs with attributes matching the values specifIEd are
displayed in the PropertyGrID. The default is an AttributeCollection
containing only browsableAttribute.Yes.

但它是如何工作的?

.NET Framework有两种机制来查找类型的元数据:

>反思API
> TypeDescriptor机制

通过类型的反射返回的元数据是不可扩展的,并且在编译类型后无法修改,而TypeDescriptor返回的元数据可以使用IExtenderProvIDer,ITypeDescriptorFilterService或ICustomTypeDescriptor进行更改.

例如,这是类型描述机制,它使设计人员能够添加一些设计时属性,这些属性不是对象的实际属性,如ModifIEr,Locked或GenerateMember.

PropertyGrID使用TypeDescriptor机制以这种方式获取属性:

var propertIEs = TypeDescriptor.GetPropertIEs(component,attributes);

这依赖于TypeDescriptor.GetProperties方法,您可以在文档的备注部分找到过滤规则.

上述方法中的组件是PropertyGrID的Selectedobject,属性是BrowsableAttributes属性,如文档中所述,只有属性与指定值匹配的属性才会显示在PropertyGrID中.由于默认情况下基于约定我们期望具有[Brawsable(false)]的属性不会显示在PropertyGrID中,因此该属性包含带有Yes值的browsable属性.

总结

以上是内存溢出为你收集整理的c# – PropertyGrid.BrowsableAttributes有什么兴趣?全部内容,希望文章能够帮你解决c# – PropertyGrid.BrowsableAttributes有什么兴趣?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1220148.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存