考虑以下对象:
Controller controller = new Controller()
{
Name = "Test",
Actions = new Action[]
{
new Action() { Name = "Action1", HttpCache = 300 },
new Action() { Name = "Action2", HttpCache = 200 },
new Action() { Name = "Action3", HttpCache = 400 }
}
};
我该如何将这个对象映射到以下形式的字典中?
#key# -> #value#
"Test.Action1" -> 300
"Test.Action2" -> 200
"Test.Action3" -> 400
也就是说,一个 Dictionary<string, int>
。
我对 LINQ 解决方案很感兴趣,但我无法解决它。
我试图将每个操作映射到一个 KeyValuePair,但我不知道如何获取每个操作的父控制器的 Name 属性。