反射以获取 UWP 中的公共实例属性 [英] Reflection to get public instance properties in UWP
本文介绍了反射以获取 UWP 中的公共实例属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 Silverlight 应用程序移植到 UWP.在我的 Silverlight 应用程序中,我获得了公共实例属性:
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);
在 UWP 中,GetProperties(BindingFlags.Instance | BindingFlags.Public) 方法似乎不再可用.在 UWP 中还有其他方法可以完成此操作吗?
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?
谢谢.
推荐答案
从此 MSDN 源码,可以进行如下操作:
From this MSDN source, you can do the following:
var props = t.GetTypeInfo().DeclaredProperties
.Where(x => x.GetMethod.IsPublic);
这篇关于反射以获取 UWP 中的公共实例属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文