说我的appsettings.json文件中有一个类似的部分。
"FileSettings": {
"File1": {
"Schedule": "1030"
},
"File2": {
"Schedule": "1130"
}
}
我想要一个具有这样的值的匿名对象的列表,但是schedule为null。
{File1, 1030}
{File2,1130}
var fileList = (from a in fileSection
select new {
FileName = a.Key,
Schedule = fileSection.Where(b => b.Key == a.Key)
.FirstOrDefault().GetSection(a.Key + ":" + "Schedule").Value
}).ToList();
答案 0 :(得分:1)
您可以像这样获得文件设置的children元素。
var fileSection = Configuration.GetSection("FileSettings").GetChildren();
var fileList = (from a in fileSection
select new
{
FileName = a.Key,
Schedule = fileSection.Where(b => b.Key == a.Key)
.FirstOrDefault().GetSection("Schedule").Value
}).ToList();