Пример #1
0
        public List <HttpAction> Regist(IServiceCollection services, Assembly assembly)
        {
            List <HttpAction> result = new List <HttpAction>();

            var list = assembly.GetTypes().Where(type => type.GetCustomAttribute <ControllerAttribute>() != null).ToList();

            foreach (var controllerType in list)
            {
                var actionList = RouteHelper.GetActions(controllerType);
                this.Regist(services, actionList);
                result.AddRange(actionList);
            }

            services.AddSingleton(GetRouterMap());

            return(result);
        }
Пример #2
0
        public void Add(string[] block, int depth, T value)
        {
            var currentWord  = block[depth];
            var replacedWord = RouteHelper.IsParameter(currentWord) ? _parameterWord : currentWord.ToLower();

            if (childrun.TryGetValue(replacedWord, out var child) == false)
            {
                string fullPath = string.Join('/', block, 0, depth + 1);
                child = new RouterNode <T>(depth, replacedWord, fullPath);

                this.childrun.Add(child.word, child);
            }

            depth++;

            if (depth < block.Length)
            {
                child.Add(block, depth, value);
            }
            else
            {
                child.Value = value;
            }
        }