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

旧巷老猫 提交于 2019-12-08 06:18:51

问题


I need to access to Type.GetProperties in my UWP platform, but my Type class lags of that method.

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.

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

Maybe there is something wrong in my nuget configuration?

The conditional compilation symbols of the project are:

NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS

I tried with and without "Compile with .NET Native tool chain" option.

The Target is Universal Windows

The Target version is: Windows 10 (10.0; Build 10586) The Min version is: Windows 10 (10.0; Build 10240)

but I also tried with Min version: Windows 10 (10.0; Build 10586)

and in NuGET, the project only has Microsoft.NETCore.UniversalWindowsPlatform v5.0.0


回答1:


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.aspx https://msdn.microsoft.com/en-us/library/system.reflection.typeinfo%28v=vs.110%29.aspx

See Reflection section in this post for more info: https://blogs.msdn.microsoft.com/dotnet/2016/02/10/porting-to-net-core/



来源:https://stackoverflow.com/questions/35449747/why-my-uwp-app-cant-call-to-type-getproperties-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!