/// <summary> /// Traverses the specified path, inserting <see cref="BranchNode"/>s as necessary, until the end of the path /// is reached, at which point the <paramref name="leafNodeProvider"/> is called to provide a leaf node to insert. /// </summary> protected void Insert(Path path, int pathDepth, Converter <PathSegment, ActionModelNode> leafNodeProvider) { int segmentCount = path.Segments.Count; if (segmentCount < 2) { throw new ArgumentException(SR.ExceptionInvalidActionPath); } PathSegment segment = path.Segments[pathDepth]; if (pathDepth + 1 == segmentCount) { // this is the last path segment -> leaf node _childNodes.Add(leafNodeProvider(segment)); } else { ActionModelNode child = FindChild(segment); if (child == null) { child = new BranchNode(segment); _childNodes.Add(child); } child.Insert(path, pathDepth + 1, leafNodeProvider); } }
/// <summary> /// Traverses the specified path, inserting <see cref="BranchNode"/>s as necessary, until the end of the path /// is reached, at which point the <paramref name="leafNodeProvider"/> is called to provide a leaf node to insert. /// </summary> protected void Insert(Path path, int pathDepth, Converter<PathSegment, ActionModelNode> leafNodeProvider) { int segmentCount = path.Segments.Count; if (segmentCount < 2) throw new ArgumentException(SR.ExceptionInvalidActionPath); PathSegment segment = path.Segments[pathDepth]; if (pathDepth + 1 == segmentCount) { // this is the last path segment -> leaf node _childNodes.Add(leafNodeProvider(segment)); } else { ActionModelNode child = FindChild(segment); if (child == null) { child = new BranchNode(segment); _childNodes.Add(child); } child.Insert(path, pathDepth + 1, leafNodeProvider); } }