Aqueduct.ServerDensity.Helpers.ToQueryString C# (CSharp) Method

ToQueryString() public static method

Constructs a NameValueCollection into a query string.
Consider this method to be the opposite of "System.Web.HttpUtility.ParseQueryString"
public static ToQueryString ( this parameters, String delimiter = "&", System.Boolean omitEmpty = true ) : string
parameters this The NameValueCollection
delimiter String The String to delimit the key/value pairs
omitEmpty System.Boolean
return string
        public static string ToQueryString(this NameValueCollection parameters, String delimiter = "&", Boolean omitEmpty = true)
        {
            if (parameters == null)
                return string.Empty;

            if (String.IsNullOrEmpty(delimiter))
                delimiter = "&";

            Char equals = '=';
            List<String> items = new List<String>();

            for (int i = 0; i < parameters.Count; i++)
            {
                foreach (String value in parameters.GetValues(i))
                {
                    Boolean addValue = (omitEmpty) ? !String.IsNullOrEmpty(value) : true;
                    if (addValue)
                        items.Add(String.Concat(parameters.GetKey(i), equals, HttpUtility.UrlEncode(value)));
                }
            }

            return String.Join(delimiter, items.ToArray());
        }
    }