- 利用反射將字符串轉換爲類類型和方法
說明: 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