/// <summary>
        /// Initializes 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)
        {
            Guard.ArgumentNotNull(segment, "segment");

            _segment         = segment._segment;
            _selector        = segment._selector;
            _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)
        {
            Guard.ArgumentNotNull(segment, "segment");

            CheckParsePath();

            AddPathSegments(new[] { 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()
        {
            var segments = InternalPathSegments;

            segments.Clear();

            if (!string.IsNullOrEmpty(_pathInternal))
            {
                foreach (var segment in UriPathSegment.FromStrings(UriPathSegment.GetPathSegments(_pathInternal)))
                {
                    if (segment != null)
                    {
                        segment.Formatter = this;
                        segments.Add(segment);
                    }
                }
            }
        }
        /// <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);
            }
        }
        /// <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.Count < index + 1)
            {
                var copySegments = new UriPathSegment[index + 1];
                segments.CopyTo(copySegments, 0);
                segments = copySegments;
            }

            if (segments[index] == null)
            {
                segments[index] = new UriPathSegment {
                    Formatter = this
                };
                PathSegments = segments;
            }

            return(segments[index]);
        }
 /// <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)));
 }
示例#8
0
 /// <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>
        /// Initializes 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)
        {
            Guard.ArgumentNotNull(segment, "segment");

            _segment = segment._segment;
            _selector = segment._selector;
            _text = segment._text;
            _requiresParse = segment._requiresParse;
            _requiresRebuild = segment._requiresRebuild;
        }