反射

2019-02-26  本文已影响0人  jojo911
public class ReflectData
{
    public int id;
    public string name;
}

public class ReflectTest反射
{
    public void test()
    {
        ReflectData data = new ReflectData();
        data.id = 911;
        data.name = "ljc";
             

        System.Type t = typeof(ReflectData);
        FieldInfo info = t.GetField("name");
        object name = info.GetValue(data);
        Debug.Log(name as string); //打印结果为ljc
    }
}
上一篇下一篇

猜你喜欢

热点阅读