unity5.x workaround for Reflection API not available in WP8.1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.