I am writing a wrapper around web services by third party. The interface looks like this:
public System.Data.DataSet GetXxxx(string functionName, object[][] parameters)
Some of the functionNames use no parameters, some of them use one, some of them more, like this (from their doc):
parameters[0][0]: @key_one
parameters[0][1]: value for @key_one
parameters[1][0]: @key_two
parameters[1][1]: value for @key_two
To generalize the wrapper, I was thinking about passing Hashtable or Dictionary<string, object>, and to create the parameters[][] inside the wrapper dynamically.
How can I do that?
Update: Actually, the parameter pairs have to keep the order. Do, I have to change the interface to something like:
using ListOfParamPairs = List<KeyValuePair<string, object>>;
...
public static DataSet GetXxxx(string functionName, ListOfParamPairs parameters)
{
...
}
var dictionary = parameters.ToDictionary(line => line[0].ToString(), line => line[1]);? Back:object[][] parameters = dictionary.Select(pair => new object[] {pair.Jey, pair.Value}).ToArray();Dictionary<K, V>doesn't have any order. If order of the pararmeters matters, yes, you have to switch toList<KeyValue<K, V>>or alike