string method = Request["METHAD"];
string ClassNamespace = method.Substring(0, method.LastIndexOf("."));// "Bss.Web.Login";
object objType = CreateObject(Request["DLL"], ClassNamespace);
//Assembly assembly = Assembly.Load("Mobizone.BLL");
//Type type = assembly.GetType("Mobizone.BLL." + dataSource.Split('.')[0]);
//object obj = Activator.CreateInstance(type); 实例化反射类
Type ht = objType.GetType();
MethodInfo methodInfo = ht.GetMethod(method.Substring(method.LastIndexOf(".") + 1));
int length = Request.Form.AllKeys.Length;
ParameterInfo[] paramsInfo = methodInfo.GetParameters();//得到指定方法的参数列表
object[] obj = new object[length];
for (int i = 0; i < length; i++)
{
C#反射实例化类并调用带参数的方法
最新推荐文章于 2021-06-20 00:03:00 发布
通过C#的反射API,动态获取类的方法名并实例化对象,然后根据HTTP请求参数创建与方法参数匹配的对象数组,最终执行指定方法。涉及到的方法包括:GetMethod、Activator.CreateInstance和Invoke。
摘要由CSDN通过智能技术生成