相关疑难解决方法(0)

TypeDescriptor.GetProperties()vs Type.GetProperties()

请考虑以下代码.

Object obj;
PropertyDescriptorCollection A = TypeDescriptor.GetProperties(obj);
PropertyInfo[] B = obj.GetType().GetProperties(); // EDIT*
Run Code Online (Sandbox Code Playgroud)

我试图理解A和B之间的区别.根据我的理解,TypeDescriptor.GetProperties()将返回自定义TypeDescriptor属性,其中Type.GetProperties()将仅返回对象的内在"真实"属性.这是正确的吗?如果obj没有任何自定义TypeDescriptor属性,那么它只是默认返回对象的文字内在属性.


* EDIT之前的原始第二行代码(返回值错误):

PropertyDescriptorCollection B = obj.GetType().GetProperties();

c# reflection types typedescriptor

32
推荐指数
3
解决办法
2万
查看次数

标签 统计

c# ×1

reflection ×1

typedescriptor ×1

types ×1