private void LoadActionRoute(Type t, RouteAttribute a1) { // 只查找公开的实例方法 var methods = t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); foreach (MethodInfo m in methods) { RouteUrlAttribute a2 = m.GetMyAttribute <RouteUrlAttribute>(); if (a2 != null) { RoutingAction obj = new RoutingAction { Attr = a2, Method = m, ServiceType = t }; if (a2.Regex != null) { _regexList.Add(obj); } else { _urlDict.AddValue(a2.Url, obj); } } } }
private bool LoadHandlerRoute(Type t) { RouteUrlAttribute a1 = t.GetMyAttribute <RouteUrlAttribute>(); if (a1 != null) { if (t.IsCompatible(typeof(IHttpHandler)) == false) { throw new InvalidCodeException("标记[RouteUrl]的类型必须实现IHttpHandler接口。"); } if (string.IsNullOrEmpty(a1.Url)) { throw new InvalidCodeException("[RouteUrl]的Url属性不能为空。"); } RoutingHandler obj = new RoutingHandler { Attr = a1, HandlerType = t }; if (a1.Regex != null) { _regexList.Add(obj); } else { _urlDict.AddValue(a1.Url, obj); } return(true); } // 返回 false 表示针对某个类型,没有找到路由标记 return(false); }