diff --git a/src/Stripe.net/Infrastructure/FormEncoding/FormEncoder.cs b/src/Stripe.net/Infrastructure/FormEncoding/FormEncoder.cs index 6a14754e6b..2926741b6c 100644 --- a/src/Stripe.net/Infrastructure/FormEncoding/FormEncoder.cs +++ b/src/Stripe.net/Infrastructure/FormEncoding/FormEncoder.cs @@ -89,7 +89,7 @@ private static string EncodeValue(object value, string key) { throw new ArgumentException( "key cannot be null or empty when value is neither an INestedOptions or an IDictionary", - "key"); + nameof(key)); } return string.Join( @@ -118,15 +118,14 @@ private static string UrlEncode(string value) /// The value for which to create the list of parameters. /// The key under which new keys should be nested, if any. /// The list of parameters - private static List FlattenParamsValue(object value, string keyPrefix) + private static List> FlattenParamsValue(object value, string keyPrefix) { - List flatParams = null; + List> flatParams = null; switch (value) { case null: - flatParams = new List(); - flatParams.Add(new Parameter(keyPrefix, string.Empty)); + flatParams = SingleParam(keyPrefix, string.Empty); break; case INestedOptions options: @@ -174,9 +173,11 @@ private static List FlattenParamsValue(object value, string keyPrefix /// The options class for which to create the list of parameters. /// The key under which new keys should be nested, if any. /// The list of parameters - private static List FlattenParamsOptions(INestedOptions options, string keyPrefix) + private static List> FlattenParamsOptions( + INestedOptions options, + string keyPrefix) { - List flatParams = new List(); + List> flatParams = new List>(); if (options == null) { return flatParams; @@ -218,9 +219,11 @@ private static List FlattenParamsOptions(INestedOptions options, stri /// The dictionary for which to create the list of parameters. /// The key under which new keys should be nested, if any. /// The list of parameters - private static List FlattenParamsDictionary(IDictionary dictionary, string keyPrefix) + private static List> FlattenParamsDictionary( + IDictionary dictionary, + string keyPrefix) { - List flatParams = new List(); + List> flatParams = new List>(); if (dictionary == null) { return flatParams; @@ -247,9 +250,11 @@ private static List FlattenParamsDictionary(IDictionary dictionary, s /// The list for which to create the list of parameters. /// The key under which new keys should be nested. /// The list of parameters - private static List FlattenParamsList(IEnumerable list, string keyPrefix) + private static List> FlattenParamsList( + IEnumerable list, + string keyPrefix) { - List flatParams = new List(); + List> flatParams = new List>(); if (list == null) { return flatParams; @@ -268,7 +273,7 @@ private static List FlattenParamsList(IEnumerable list, string keyPre * list might look like `a[0]=1&b[1]=2`. Emptying it would look like `a=`.) */ if (!flatParams.Any()) { - flatParams.Add(new Parameter(keyPrefix, string.Empty)); + flatParams.Add(new KeyValuePair(keyPrefix, string.Empty)); } return flatParams; @@ -278,10 +283,10 @@ private static List FlattenParamsList(IEnumerable list, string keyPre /// The parameter's key. /// The parameter's value. /// A list containg the single parameter. - private static List SingleParam(string key, string value) + private static List> SingleParam(string key, string value) { - List flatParams = new List(); - flatParams.Add(new Parameter(key, value)); + List> flatParams = new List>(); + flatParams.Add(new KeyValuePair(key, value)); return flatParams; } @@ -313,19 +318,5 @@ private static string NewPrefix(string key, string keyPrefix) return $"{keyPrefix}[{key.Substring(0, i)}]{key.Substring(i)}"; } } - - /// Represents a parameter in a query string, i.e. a key/value pair. - internal sealed class Parameter - { - public Parameter(string key, string value) - { - this.Key = key; - this.Value = value; - } - - public string Key { get; } - - public string Value { get; } - } } }