Beispiel #1
0
        /// <summary>
        ///     Sorts a <see cref="WebParameterCollection" /> by name, and then value if equal.
        /// </summary>
        /// <param name="parameters">A collection of parameters to sort</param>
        /// <returns>A sorted parameter collection</returns>
        public static WebParameterCollection SortParametersExcludingSignature(WebParameterCollection parameters)
        {
            var copy       = new WebParameterCollection(parameters);
            var exclusions = copy.Where(n => n.Name.EqualsIgnoreCase("oauth_signature"));

            copy.RemoveAll(exclusions);
            copy.ForEach(p =>
            {
                p.Name  = UrlEncodeStrict(p.Name);
                p.Value = UrlEncodeStrict(p.Value);
            });
            copy.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name) != 0
                ? string.CompareOrdinal(x.Name, y.Name)
                : string.CompareOrdinal(x.Value, y.Value));

            return(copy);
        }