private void LinkSegment(UriPathSegment segment) { if (segment != null) { segment.Formatter = this; } }
/// <summary> /// Initialises a new instance of the <see cref="UriPathSegment"/> class with /// the details of the specified segment. /// </summary> /// <param name="segment">The segment to copy the details from.</param> public UriPathSegment(UriPathSegment segment) { _segment = segment._segment; _predicate = segment._predicate; _text = segment._text; _requiresParse = segment._requiresParse; _requiresRebuild = segment._requiresRebuild; }
/// <summary> /// Adds the specified paths to the <see cref="Uri"/>. /// </summary> /// <param name="segment">The path segment to add to the <see cref="Uri"/>.</param> public UriFormatter AppendPath(UriPathSegment segment) { CheckParsePath(); InternalPathSegments.Add(segment); LinkSegment(segment); RequiresRebuildPath = true; return(this); }
/// <summary> /// Called when the <see cref="Path"/> needs to be rebuilt. /// </summary> protected virtual void OnBuildPath() { var path = new StringBuilder(); foreach (var segment in _pathSegments) { if (segment != null) { UriPathSegment.AppendPath(path, segment.Segment); } } PathInternal = path.ToString(); }
/// <summary> /// Called when the <see cref="Path"/> needs to be parsed. /// </summary> protected virtual void OnParsePath() { if (!string.IsNullOrEmpty(PathInternal)) { var segments = InternalPathSegments; segments.Clear(); foreach (var segment in UriPathSegment.FromStrings(UriPathSegment.GetPathSegments(PathInternal))) { if (segment != null) { LinkSegment(segment); segments.Add(segment); } } } }
/// <summary> /// Returns the segment at the specified index. /// </summary> /// <param name="index">The index of the segment.</param> /// <returns>The segment at the specified index.</returns> /// <remarks>If the <paramref name="index"/> is past the end of the current array the length is increased.</remarks> public UriPathSegment GetPathSegment(int index) { var segments = PathSegments; if (segments.Length < index + 1) { var copySegments = new UriPathSegment[index + 1]; Array.Copy(segments, copySegments, segments.Length); segments = copySegments; } if (segments[index] == null) { segments[index] = new UriPathSegment(); LinkSegment(segments[index]); PathSegments = segments; } return(segments[index]); }
/// <summary> /// Initialises a new instance of the <see cref="UriFormatter"/> class with /// the specified <see cref="Uri"/>. /// </summary> /// <param name="uri">The <see cref="Uri"/> to assign.</param> public UriFormatter(UriFormatter uri) { _uri = uri._uri; _requiresParseUri = uri._requiresParseUri; _requiresRebuildUri = uri._requiresRebuildUri; _scheme = uri._scheme; _port = uri._port; _host = uri._host; _pathPrefix = uri._pathPrefix; _server = uri._server; _fragment = uri._fragment; PathInternal = uri.PathInternal; _directPath = uri._directPath; _requiresParsePath = uri._requiresParsePath; _requiresRebuildPath = uri._requiresRebuildPath; if (uri._pathSegments != null) { _pathSegments = new List <UriPathSegment>(uri._pathSegments.Count); foreach (var segment in uri._pathSegments) { var clone = new UriPathSegment(segment) { Formatter = this }; _pathSegments.Add(clone); } } if (uri._queryArgs != null) { _queryArgs = new QueryArgsDictionary(this, uri._queryArgs); } }
/// <summary> /// Builds a local path from the specified segments. /// </summary> /// <param name="segments">Array of path segments.</param> public SDataUri BuildLocalPath(params string[] segments) { return(BuildLocalPath(UriPathSegment.FromStrings(segments))); }
/// <summary> /// Sets the path for the <see cref="Uri"/>. /// </summary> /// <param name="segments">The path segments for the <see cref="Uri"/>.</param> public UriFormatter SetPath(params string[] segments) { return(SetPath(UriPathSegment.FromStrings(segments))); }
/// <summary> /// Returns the segment at the specified index. /// </summary> /// <param name="index">The index of the segment.</param> /// <returns>The segment at the specified index.</returns> /// <remarks>If the <paramref name="index"/> is past the end of the current array the length is increased.</remarks> public UriPathSegment GetPathSegment(int index) { var segments = PathSegments; if (segments.Length < index + 1) { var copySegments = new UriPathSegment[index + 1]; Array.Copy(segments, copySegments, segments.Length); segments = copySegments; } if (segments[index] == null) { segments[index] = new UriPathSegment(); LinkSegment(segments[index]); PathSegments = segments; } return segments[index]; }
/// <summary> /// Adds the specified paths to the <see cref="Uri"/>. /// </summary> /// <param name="segment">The path segment to add to the <see cref="Uri"/>.</param> public UriFormatter AppendPath(UriPathSegment segment) { CheckParsePath(); InternalPathSegments.Add(segment); LinkSegment(segment); RequiresRebuildPath = true; return this; }
/// <summary> /// Initialises a new instance of the <see cref="UriFormatter"/> class with /// the specified <see cref="Uri"/>. /// </summary> /// <param name="uri">The <see cref="Uri"/> to assign.</param> public UriFormatter(UriFormatter uri) { _uri = uri._uri; _requiresParseUri = uri._requiresParseUri; _requiresRebuildUri = uri._requiresRebuildUri; _scheme = uri._scheme; _port = uri._port; _host = uri._host; _pathPrefix = uri._pathPrefix; _server = uri._server; _fragment = uri._fragment; PathInternal = uri.PathInternal; _directPath = uri._directPath; _requiresParsePath = uri._requiresParsePath; _requiresRebuildPath = uri._requiresRebuildPath; if (uri._pathSegments != null) { _pathSegments = new List<UriPathSegment>(uri._pathSegments.Count); foreach (var segment in uri._pathSegments) { var clone = new UriPathSegment(segment) {Formatter = this}; _pathSegments.Add(clone); } } if (uri._queryArgs != null) _queryArgs = new Dictionary<string, string>(uri._queryArgs, StringComparer.InvariantCultureIgnoreCase); }
private void LinkSegment(UriPathSegment segment) { if (segment != null) segment.Formatter = this; }