I have a class A containing an array of key/values pairs described by class B. One of the key is called "name". I want to use Linq to build a Dictionary<string, Dictionary<string, string>> where key of first dictionary is the attribute called "name" in the B array and the value is a second dictionary that contains the key/value pairs of B.
public class A
{
public int a;
public B[] b;
}
public class B
{
public string key;
public string value;
}
A[] a = new A[]
{
new A { a = 1, b = new B[] { new B { key = "name", value = "n1"}, new B { key = "test", value = "t1" } }, },
new A { a = 2, b = new B[] { new B { key = "name", value = "n2"}, new B { key = "test", value = "t2" } }, },
};
So in fact I would like to build the following dictionary using Linq on array "a":
Dictionary<string, Dictionary<string, string>> d = new Dictionary<string, Dictionary<string, string>>()
{
{ "n1", new Dictionary<string, string>() { { "name", "n1" }, { "test", "t1" } } },
{ "n2", new Dictionary<string, string>() { { "name", "n2" }, { "test", "t2" } } },
};