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 #