Why my UWP app can't call to Type.GetPropertie

2019-05-29 13:06发布

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条回答
Bombasti
2楼-- · 2019-05-29 13:34

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/

查看更多
登录 后发表回答