Ric*_*ter 23 c# reflection microsoft-metro windows-8 windows-runtime
我正在尝试将一个简单的应用程序移植到Windows 8 Metro(WinRT).似乎缺少一些非常基本的方法.一个基本的例子:Type.GetProperty().它适用于Windows Phone 7,Silverlight和.NET客户端配置文件.我是否必须安装某些东西(例如,一个特殊的库),或者这种方法在.NET metro配置文件中根本不可用?
UPDATE
好的谢谢.现在我用this.GetType().GetTypeInfo().DeclaredProperties.
using System.Reflection;需要有这种GetTypeInfo()扩展方法.
red*_*t84 12
除了Nicholas Butler的回复之外,我最终还是使用了这种扩展来维护代码在所有平台上的可重用性.
#if NETFX_CORE // Workaround for .Net for Windows Store not having Type.GetProperty method
public static class GetPropertyHelper
{
public static PropertyInfo GetProperty(this Type type, string propertyName)
{
return type.GetTypeInfo().GetDeclaredProperty(propertyName);
}
}
#endif
Run Code Online (Sandbox Code Playgroud)
这种方式Type.GetProperty()适用于所有平台.