public bool TryGet(string[] block, int depth, out RouterNode <T> result) { var word = block[depth]; if (this.childrun.TryGetValue(word.ToLower(), out result) == false) { if (this.childrun.TryGetValue(_parameterWord, out result) == false) { return(false); } } depth++; if (depth < block.Length) { return(result.TryGet(block, depth, out result)); } else { return(true); } }
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; } }
public Router() { _rootNode = new RouterNode <HttpAction>(); }