为什么我的 UWP 应用无法调用 Type.GetProperties 方法? [英] Why my UWP app can't call to Type.GetProperties method?
问题描述
我需要在 UWP 平台中访问 Type.GetProperties,但我的 Type 类滞后于该方法.
I need to access to Type.GetProperties in my UWP platform, but my Type class lags of that method.
在我看来,这是因为我们在 UWP 中使用了子集方法,但是在尝试查找信息时,我发现了这一点:Type.GetProperties() 在 Release 中不起作用,因此该方法确实存在于 UWP 中.
In my mind it's because of the subset methods we have in UWP, but trying to find information, I found this: Type.GetProperties() doesn't work in Release so that method really exists in UWP.
如果我去看Type的定义,第一行是这样的:
If I go to the definition of Type, the first lines are like this:
#region Assembly System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// C:\Users\JoséÁngel\.nuget\packages\System.Runtime\4.0.20\ref\dotnet\System.Runtime.dll
#endregion
也许我的 nuget 配置有问题?
Maybe there is something wrong in my nuget configuration?
项目的条件编译符号为:
The conditional compilation symbols of the project are:
NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS
我尝试使用和不使用使用 .NET Native 工具链编译"选项.
I tried with and without "Compile with .NET Native tool chain" option.
目标是通用 Windows
The Target is Universal Windows
目标版本为:Windows 10 (10.0; Build 10586)最低版本为:Windows 10 (10.0; Build 10240)
The Target version is: Windows 10 (10.0; Build 10586) The Min version is: Windows 10 (10.0; Build 10240)
但我也尝试过最小版本:Windows 10 (10.0; Build 10586)
but I also tried with Min version: Windows 10 (10.0; Build 10586)
在 NuGET 中,项目只有 Microsoft.NETCore.UniversalWindowsPlatform v5.0.0
and in NuGET, the project only has Microsoft.NETCore.UniversalWindowsPlatform v5.0.0
推荐答案
如链接问题的答案中所述,将您的类型添加到 .net 本机动态列表,然后使用 *yourthing*.GetType().GetTypeInfo().DeclaredProperties
.
Add your type to the .net native dynamic list as explained in the linked question's answer, and then use *yourthing*.GetType().GetTypeInfo().DeclaredProperties
.
https://msdn.microsoft.com/en-us/library/system.reflection.introspectionextensions.gettypeinfo%28v=vs.110%29.aspxhttps://msdn.microsoft.com/en-us/library/system.reflection.typeinfo%28v=vs.110%29.aspx
有关详细信息,请参阅本文中的反射"部分:https://blogs.msdn.microsoft.com/dotnet/2016/02/10/porting-to-net-core/
See Reflection section in this post for more info: https://blogs.msdn.microsoft.com/dotnet/2016/02/10/porting-to-net-core/
这篇关于为什么我的 UWP 应用无法调用 Type.GetProperties 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!