/* * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Net; using Amazon.Runtime; using Amazon.Runtime.Internal.Util; using Amazon.Runtime.Internal.Auth; using Amazon.Util; namespace Amazon.Runtime.Internal { /// /// Collection of parameters that an SDK client will send to a service. /// public class ParameterCollection : SortedDictionary { /// /// Constructs empty ParameterCollection. /// public ParameterCollection() : base(comparer: StringComparer.Ordinal) { } /// /// Adds a parameter with a string value. /// /// /// public void Add(string key, string value) { Add(key, new StringParameterValue(value)); } /// /// Adds a parameter with a list-of-strings value. /// /// /// public void Add(string key, List values) { Add(key, new StringListParameterValue(values)); } /// /// Converts the current parameters into a list of key-value pairs. /// /// public List> GetSortedParametersList() { return GetParametersEnumerable().ToList(); } private IEnumerable> GetParametersEnumerable() { foreach (var kvp in this) { var name = kvp.Key; var value = kvp.Value; var spv = value as StringParameterValue; var slpv = value as StringListParameterValue; if (spv != null) yield return new KeyValuePair(name, spv.Value); else if (slpv != null) { var sortedList = slpv.Value; sortedList.Sort(StringComparer.Ordinal); foreach (var listValue in sortedList) yield return new KeyValuePair(name, listValue); } else { throw new AmazonClientException("Unsupported parameter value type '" + value.GetType().FullName + "'"); } } } } }