Reflection to get public instance properties in UW

2019-09-11 10:45发布

问题:

I am porting a Silverlight application to UWP. In my Silverlight app, i get the public instance properties:

Type t;
t.GetProperties(BindingFlags.Instance | BindingFlags.Public);

In UWP it look like the GetProperties(BindingFlags.Instance | BindingFlags.Public) method is no longer available. Is there another way to accomplish this in UWP?

thank you.

回答1:

From this MSDN source, you can do the following:

var props = t.GetTypeInfo().DeclaredProperties
                           .Where(x => x.GetMethod.IsPublic);