Пример #1
0
        /// <summary>
        /// Construct a URI as defined by the parts of this request builder.
        /// </summary>
        /// <returns>A <see cref="System.Uri"/> for this request.</returns>
        /// <remarks>Method is not included in the Uri.</remarks>
        public Uri BuildUri()
        {
            var restPath = new StringBuilder(PathParameters
                                             .Select(param => new { Token = "{" + param.Key + "}", Value = Uri.EscapeDataString(param.Value) })
                                             .Aggregate(this.Path, (path, param) => path.Replace(param.Token, param.Value)));

            if (QueryParameters.Count > 0)
            {
                restPath.Append("?");
                restPath.Append(String.Join("&", QueryParameters.Select(
                                                x => String.Format("{0}={1}", Uri.EscapeDataString(x.Key), Uri.EscapeDataString(x.Value)))
                                            .ToArray()));
            }

            return(UriFactory.Create(this.BaseUri, restPath.ToString()));
        }
        /// <summary>
        /// Construct a URI as defined by the parts of this request builder.
        /// </summary>
        /// <returns>A <see cref="System.Uri"/> for this request.</returns>
        /// <remarks>Method is not included in the Uri.</remarks>
        public Uri BuildUri()
        {
            var restPath = new StringBuilder(PathParameters
                                             .Select(param => new { Token = "{" + param.Key + "}", Value = Uri.EscapeDataString(param.Value) })
                                             .Aggregate(this.Path, (path, param) => path.Replace(param.Token, param.Value)));

            if (QueryParameters.Count > 0)
            {
                restPath.Append("?");
                // If paramter value is empty - just add the "name", otherwise "name=value"
                restPath.Append(String.Join("&", QueryParameters.Select(
                                                x => x.Value.IsNullOrEmpty() ?
                                                Uri.EscapeDataString(x.Key) :
                                                String.Format("{0}={1}", Uri.EscapeDataString(x.Key), Uri.EscapeDataString(x.Value)))
                                            .ToArray()));
            }

            return(UriFactory.Create(this.BaseUri, restPath.ToString()));
        }