- 利用反射将字符串转换为类类型和方法
说明: voidname: 指方法的字符串名称.
Type type = System.Type.GetType("AllenExcelImport.DAL.CostRecImport"); //得到类类型,类必须全路径 Object obj = Activator.CreateInstance(type); //得到命名空间名 MethodInfo methodinfo = type.GetMethod(voidname); //得到方法 string msg = (string)methodinfo.Invoke(obj, new object[] { lstT,Convert.ToInt32(txtfyear.Text.Trim()) });
参考:https://blog.csdn.net/weixin_30300225/article/details/97726971