Write a little before work, although it took a lot of time but the final solution is relatively simple.
The first method: use the class in WinRTLegacy.dll . This DLL in the generated WP project comes with no need to add it in the Unity project, but the problem is that it's inconvenient to debug the code because you don't put it in the project. There is no such DLL in the VS program, which has a great impact on debug code and VS Auto-completion.
Needless to say, use a few examples to illustrate how to use:
#if netfx_core foreach (PropertyInfo p_info in Typeextensions.getpublicinstanceproperties (type)) #else foreach (PropertyInfo p_info in type. GetProperties ()) #endif # if Netfx_core propertyinfo[] Proinfos = Unity.Partial.System.Type.GetProperties ( Srcobj.gettype (), m_bindingattr); #else propertyinfo[] Proinfos = Srcobj.gettype (). GetProperties (m_bindingattr); #endif
Typeextensions is the addition of unity to the WP8.1. NET Core Removal Reflection API, the method is relatively full but compared with the original type class method than still have a lot of shortcomings, Fortunately there is another class Unity.Partial.System.Type to add.
#if netfx_core foreach (FieldInfo f_info in Unity.Partial.System.Type.GetFields (Type)) #else foreach ( FieldInfo f_info in type. GetFields ()) #endif
These two classes are all in the same DLL, with Object Browser to see this DLL really a bit messy. Working with these two classes will solve most of the reflection API's problems.
The second approach: using a runtime method like Getruntimemethods
Ienumerable<methodinfo> methods = Type. Getruntimemethods ();
It is also possible to find a large number of method names with runtime in the Object Browser, which are valid under WP8.1.
PS: Macro Netfx_core does not need to be defined in the Unity project and comes in the generated WP project.
unity5.x workaround for Reflection API not available in WP8.1