Skip to content

Instantly share code, notes, and snippets.

@nozzlegear
Created July 21, 2017 15:39
Show Gist options
  • Save nozzlegear/14eb07ce83a8bb8799ffcac24767e2b3 to your computer and use it in GitHub Desktop.
Save nozzlegear/14eb07ce83a8bb8799ffcac24767e2b3 to your computer and use it in GitHub Desktop.
Convert MVC5's QueryString to a List<KeyValuePair<string, StringValues>> needed by ShopifySharp's auth service.
namespace MyNamespace
{
public static class Extensions
{
public List<KeyValuePair<string, StringValues>> ToKvps(this System.Collections.Specialized.NameValueCollection qs)
{
Dictionary<string, string> parameters = qs.Keys.Cast<string>().ToDictionary(key => key, value => qs[value]);
var kvps = new List<KeyValuePair<string, StringValues>>();
parameters.ToList().ForEach(x =>
{
kvps.Add(new KeyValuePair<string, StringValues>(x.Key, new StringValues(x.Value)));
});
return kvps;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment