public RequestConfigActionEntity GetAction(string module, string action) { if (ActionDic.ContainsKey(module)) { if (ActionDic[module].ContainsKey(action)) { return(ActionDic[module][action]); } } return(null); }
private object RunAction(object Instance, string Action, object[] Parameters) { if (ActionDic.ContainsKey(Action)) { if (Parameters != null) { Parameters = ConvertParameterType(Parameters, ActionDic[Action]); } return(ActionDic[Action].Invoke(Instance, Parameters)); } else { throw new Exception("Action not found"); } }
public bool LoadAssembly(string Path) { try { if (!DllPathDic.Contains(Path)) { Assembly assembly = Assembly.LoadFrom(Path); List <Type> types = assembly.GetTypes().ToList(); //合并去重字典缓存 ControllerDic = ControllerDic == null ? new Dictionary <string, Type>() : ControllerDic; ControllerDic = ControllerDic.Union(types.Where(w => w.GetCustomAttribute(typeof(DescriptionAttribute), false) != null && ((DescriptionAttribute)w.GetCustomAttribute(typeof(DescriptionAttribute), false)).Description == "Controller").ToDictionary(type => type.Name.ToLower(), type => type)).ToDictionary(t => t.Key, t => t.Value); foreach (var t in types) { Attribute attr = t.GetCustomAttribute(typeof(DescriptionAttribute), false); if (attr != null && ((DescriptionAttribute)attr).Description == "Controller") { foreach (var m in t.GetMethods()) { if (!ActionDic.ContainsKey(m.Name.ToLower())) { ActionDic.Add(m.Name.ToLower(), m); } } } //ActionDic = ActionDic.Union(t.GetMethods().ToDictionary(m => m.Name.ToLower(), m => m)).ToDictionary(m => m.Key, m => m.Value); } //初始化插件数据结构 InitControllersData(); DllPathDic.Add(Path); return(true); } else { throw new Exception("程序集重复加载!"); } } catch (Exception e) { Log.Write(e.ToString()); throw e; } }