Is it possible to convert a IEnumerable<KeyValuePair<string,string>>KeyValuePair to an anonymous type?
Dictionary<string, string> dict= new Dictionary<string, string>();
dict.add("first", "hello");
dict.add("second", "world");
var anonType = new{dict.Keys[0] = dict[0], dict.Keys[1] = dict[1]};
Console.WriteLine(anonType.first);
Console.WriteLine(anonType.second);
********************output*****************
hello
world
The reason I would like to do this is because I am retrieving an object from a web service representing an object that does not exist in wsdl. The returned object contains only the KeyValuePair collection containing custom fields and their values. These custom fields can be called anything, so I can't really map the xml deserialization method to the final object that I will use (whose properties must be bound to the grid).
* Just because I used Dictionary<string,string>it does not mean that it is absolutely a dictionary, I just used it to illustrate. Indeed hisIEnumerable<KeyValuePair<string,string>>
, , . #.NET 4.0.