/// <summary> /// Called when the <see cref="Uri"/> needs to be parsed. /// </summary> protected virtual void OnParseUri() { RequiresParsePath = true; _directPath = null; if (_uri == null) { _port = UnspecifiedPort; _scheme = Http; _host = string.Empty; _pathPrefix = string.Empty; _server = string.Empty; _fragment = string.Empty; PathInternal = string.Empty; _queryArgs = null; } else { _scheme = _uri.Scheme; _port = _uri.Port; _host = _uri.Host; var path = Uri.UnescapeDataString(_uri.AbsolutePath); if (path.StartsWith(PathSegmentPrefix)) { path = path.Substring(PathSegmentPrefix.Length); } var endServer = path.IndexOf(PathSegmentPrefix[0]); if (endServer < 0) { _server = path; PathInternal = string.Empty; } else { _server = path.Substring(0, endServer); PathInternal = path.Substring(endServer + 1); } _fragment = _uri.Fragment; if (_fragment.StartsWith(FragmentPrefix)) { _fragment = _fragment.Substring(FragmentPrefix.Length); } if (PathInternal.StartsWith(PathSegmentPrefix)) { PathInternal = PathInternal.Substring(PathSegmentPrefix.Length); } _queryArgs = new QueryArgsDictionary(this, _uri.Query); } }
/// <summary> /// Initializes 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) { Guard.ArgumentNotNull(uri, "uri"); _uri = uri._uri; _requiresParseUri = uri._requiresParseUri; _requiresRebuildUri = uri._requiresRebuildUri; _scheme = uri._scheme; _port = uri._port; _host = uri._host; _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); } } _query = uri._query; _requiresParseQuery = uri._requiresParseQuery; _requiresRebuildQuery = uri._requiresRebuildQuery; if (uri._queryArgs != null) { _queryArgs = new QueryArgsDictionary(this, uri._queryArgs); } }