The application of reflection technology in unity in C #

Source: Internet
Author: User

The advantage of reflection technology to assign values to classes is that it simplifies the code, and the benefits of encapsulation are obvious. The most direct use is to use in the display configuration file, the personal habitual practice is to do a VO to store the required data, the code is as follows:
Internal class BASEITEMVO {    publicstring  name;      Public string Locka;}
Use reflection to get the fields in the class:
 Public Static void SetValue (Object tar, String name, Object value) {            = tar. GetType (). GetField (name);               = Finfo.fieldtype;             if (type==typeof(String)) {     //Here you can get the type of the field in Vo                Console.WriteLine ("  This is a string");            Finfo.setvalue (tar, value);     Set the value of a field in        Vo}

Although the code is a little bit, it is very useful to read the XML configuration and simply record it.

The application of reflection technology in unity in C #

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.