/// <summary> /// Expands the specified segment collection which contains only optinal and literal segments. /// The optional segments are processed recursively and the literals are parsed for parameters. /// </summary> /// <param name="collection">The collection of segments to expand.</param> /// <param name="constraints">The constraints.</param> /// <param name="parameters">The parameters hash set to track the uniqueness.</param> /// <returns>Returns the expanded path segments tree.</returns> protected virtual PathSegmentCollection Expand(PathSegmentCollection collection, IDictionary <string, object> constraints, HashSet <string> parameters) { var result = new PathSegmentCollection(); foreach (var item in collection) { if (item is LiteralPathSegment) { var staticItem = (LiteralPathSegment)item; var list = Parse(staticItem.Text, constraints, parameters); result.AddRange(list); } else if (item is OptionalPathSegment) { var optItem = new OptionalPathSegment(); result.Add(optItem); var inner = Expand(item.Segments, constraints, parameters); optItem.Segments.AddRange(inner); } } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="PathSegment"/> class. /// </summary> public PathSegment() { this.Segments = new PathSegmentCollection(); }