问题描述
我需要使用的GetProperties 方式,所以我可以测试在一个特定的类的任何属性是否具有指定自定义属性。然而,它没有看起来好像通用的Windows应用程序支持这一点:
obj.GetType()的GetProperties()
引发错误:
'的System.Type'不包含'的GetProperties的定义,并没有扩展方法'的GetProperties接受类型'的System.Type'的第一个参数可以找到(是否缺少using指令或程序集引用?)
我需要什么,以便利用充分反映库的参考?
在此先感谢
添加到您使用的语句:
使用的System.Reflection;
然后你可以使用 obj.GetType()。GetRuntimeProperties()
方法。此方法返回指定的类型定义的所有属性,包括继承,非公,实例和静态属性。请记住,这种行为是比的GetProperties的行为()
这是只返回公共属性略有不同。
I need to use the GetProperties method so I can test whether any properties in a particular class has a specified custom attribute. However it doesn't appear as though Windows Universal Apps supports this:
obj.GetType().GetProperties()
Raises the error:
'System.Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
What do I need to reference in order to make use of the full reflection library?
Thanks in advance.
Add this to your using statements:
using System.Reflection;
Then you can use obj.GetType().GetRuntimeProperties()
method. This method returns all properties defined on the specified type, including inherited, non-public, instance, and static properties. Keep in mind that this behavior is slightly different than the behavior of GetProperties()
which is to return only the public properties.
这篇关于反思的Windows应用程序的通用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!