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#】通过反射调用某类某方法
最新推荐文章于 2025-05-09 15:28:08 发布