C#嵌套类的访问方法
C#嵌套类的访问方法
发布时间:2016-12-28 来源:查字典编辑
摘要:对于以下数据,如何在运行时通过字符串来得到静态变量UIPath的值。复制代码代码如下:publicclassGameMainMenu:UIC...

对于以下数据,如何在运行时通过字符串来得到静态变量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());

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C#教程学习
热门C#教程学习
编程开发子分类