public static void RegistController(Type t) { if (!t.GetInterfaces().Contains(typeof(IMyController))) { return; } //dynamic controller = Activator.CreateInstance(t); //自动注册该类的所有方法 string controllername = t.Name.ToLower(); ControllerDescription cd = new ControllerDescription(t); if (s_ServiceCommandDict.ContainsKey(controllername)) { return; } s_ServiceCommandDict.Add(controllername, cd); foreach (MethodInfo m in cd.ControllerType.GetMethods(ActionBindingFlags)) { ActionAttribute actionAttr = m.GetMyAttribute <ActionAttribute>(); if (actionAttr != null) { ActionDescription actionDescription = new ActionDescription(m, actionAttr) { PageController = cd }; string actionname = m.Name.ToLower(); s_PageActionDict.Add(controllername + "/" + actionname, actionDescription); } } }
public ActionDescription(MethodInfo m, ActionAttribute atrr) : base(m) { this.MethodInfo = m; this.Attr = atrr; this.Parameters = m.GetParameters(); this.HasReturn = m.ReturnType != ReflectionHelper.VoidType; }
public static void RegistController(Type t) { if (!t.GetTypeInfo().ImplementedInterfaces.Contains(typeof(IActionController))) { return; } object controller = Activator.CreateInstance(t); string controllername = t.Name; foreach (MethodInfo m in t.GetRuntimeMethods()) { ActionAttribute actionAttr = m.GetCustomAttribute <ActionAttribute>(); if (actionAttr != null) { RegistMethodInfo(controllername + "/" + m.Name, controller, m); } } }