为什么我的 UWP 应用无法调用 Type.GetProperties 方法?

Why my UWP app can't call to Type.GetProperties method?

我需要在我的 UWP 平台中访问 Type.GetProperties,但我的类型 class 滞后于该方法。

在我看来,这是因为我们在 UWP 中有子集方法,但试图查找信息,我发现了这个: 所以 UWP 中确实存在该方法。

如果我去Type的定义,第一行是这样的:

#region Assembly System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// C:\Users\JoséÁngel\.nuget\packages\System.Runtime.0.20\ref\dotnet\System.Runtime.dll
#endregion

可能是我的 nuget 配置有问题?

项目的条件编译符号为:

NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS

我试过使用和不使用 "Compile with .NET Native tool chain" 选项。

目标是通用的Windows

目标版本是:Windows10(10.0;内部版本 10586) 最小版本为:Windows 10 (10.0; Build 10240)

但我也尝试使用最小版本:Windows 10 (10.0; Build 10586)

而在 NuGET 中,该项目只有 Microsoft.NETCore.UniversalWindowsPlatform v5.0.0

按照链接问题的答案中的说明将您的类型添加到 .net 本机动态列表,然后使用 *yourthing*.GetType().GetTypeInfo().DeclaredProperties

https://msdn.microsoft.com/en-us/library/system.reflection.introspectionextensions.gettypeinfo%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/system.reflection.typeinfo%28v=vs.110%29.aspx

有关详细信息,请参阅此 post 中的反思部分:https://blogs.msdn.microsoft.com/dotnet/2016/02/10/porting-to-net-core/