string strClass = “VolumeManager”; //类名,有命名空间需要加上,namespace.class
string callMethodName = toggle.transform.parent.name; //方法名
Type t;//类型
object obj; //对象
t = Type.GetType(strClass); //通过string找到类
System.Reflection.MethodInfo method = t.GetMethod(callMethodName);//通过类找到方法method
obj = System.Activator.CreateInstance(t); //new一个类的对象
method.Invoke(obj, null); //用这个对象调用method方法
【C#】通过反射调用某类某方法
最新推荐文章于 2022-09-20 16:01:49 发布
本文介绍如何使用C#反射来动态地获取类并调用其方法,包括通过字符串查找类、获取方法信息及实例化对象等内容。
440

被折叠的 条评论
为什么被折叠?



