简体   繁体   中英

Reflection in Windows Universal Apps

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM