Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FluentQueryString"/> class.
 /// </summary>
 /// <param name="name">
 /// The query string name.
 /// </param>
 /// <param name="value">
 /// The query string value.
 /// </param>
 /// <param name="encode">
 /// Indicates whether to encode the querystring name and value.
 /// </param>
 public FluentQueryString(string name, string value, bool encode)
 {
     if (encode)
     {
         this.Name  = FluentHttpRequest.UrlEncode(name);
         this.Value = FluentHttpRequest.UrlEncode(value);
     }
     else
     {
         this.Name  = name;
         this.Value = value;
     }
 }
        /// <summary>
        /// Appends the form parameters.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// The fluent http request body.
        /// </returns>
        public FluentHttpRequestBody Append(IDictionary <string, object> parameters)
        {
            if (parameters == null || parameters.Count == 0)
            {
                return(this);
            }

            var sb = new StringBuilder();

            foreach (var parameter in parameters)
            {
                sb.AppendFormat("{0}={1}&", FluentHttpRequest.UrlEncode(parameter.Key), FluentHttpRequest.UrlEncode(parameter.Value.ToString()));
            }

            // remove the last &
            --sb.Length;

            return(Append(sb.ToString()));
        }