软件编程
位置:首页>> 软件编程>> C#编程>> C#嵌套类的访问方法

C#嵌套类的访问方法

作者:junjie  发布时间:2021-07-26 18:03:20 

标签:C#,嵌套类,访问方法

对于以下数据,如何在运行时通过字符串来得到静态变量UIPath的值。


public class GameMainMenu : UIClass
{
    public class JetPack : UIClass
    {
        public static UIPath UIPath = new UIPath("UIPrefabs/GameMainMenu/JetPack/JetPack.prefab");
    }
}

像下面这样即可。


BindingFlags flag = BindingFlags.Static | BindingFlags.Public;
Type type = Type.GetType("GameMainMenu+JetPack");
System.Reflection.FieldInfo key = type.GetField("UIPath", flag);
Debug.Log((key.GetValue(null) as UIPath).ToString());

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com