C#反射运行该类下的方法

 

Text:反射的类名

s:方法名

data:参数

 

如果无参则:

(string)method.Invoke(obj, null);

 

Type type = typeof(Text);
MethodInfo method = type.GetMethod("s");
ceshi data =new ceshi();
object[] parameters = new object[] {data};
object obj = Activator.CreateInstance(type);
string result = (string)method.Invoke(obj, parameters);

posted @ 2022-06-28 11:34  园友2288976  阅读(118)  评论(0编辑  收藏  举报