/// <summary> /// 利用反射调用插件方法 /// 涂聚文(Geovin Du) /// 2019-03-27 /// /// </summary> /// <param name="assemblyName">生成类库文件名称</param> /// <param name="className">类名</param> /// <param name="methodName">方法名</param> /// <param name="objParas">参数</param> /// <returns>DataTable</returns> public DataTable getMethod(string assemblyName, string className, string methodName, params object[] objParas) { DataTable dt = new DataTable(); try { Assembly assembly = Assembly.Load(assemblyName);//生成类库文件名称 放在BIN文件夹下的类库文件DLL的名称 object obj = assembly.CreateInstance("DuCms.Web.Plugin." + assemblyName + "." + className); //类库名称+类名称 Type t = obj.GetType(); //查找匹配的方法 foreach (MethodInfo m in t.GetMethods(BindingFlags.Instance | BindingFlags.Public)) { if (m.Name == methodName && m.GetParameters().Length == objParas.Length) { object obj2 = m.Invoke(obj, objParas); dt = obj2 as DataTable; return dt; } } } catch { //插件方法获取失败 } return dt; }
调用:
DataTable backList = get_plugin_method("DuCms.Web.Plugin.Feedback", "Feedback", "getFeedbackList", 4, "IsLock=0 and SiteId="+Site.Id); foreach(DataRow dr in backList.Rows) { 。。。。 }
Feedback 类
namespace DuCms.Web.Plugin.Feedback { /// <summary> /// /// </summary> public partial class Feedback : Web.UI.Page { /// <summary> /// 留言分页列表 /// </summary> /// <param name="page_size">页面大小</param> /// <param name="page_index">当前页码</param> /// <param name="strwhere">查询条件</param> /// <param name="totalcount">总记录数</param> /// <returns>DateTable</returns> public DataTable getFeedbackList(int pageSize, int pageIndex, string strWhere, out int totalCount) { ..... } } }