检索config.json部分在ASP.NET 5 [英] Retrieve sections from config.json in ASP.NET 5
问题描述
让我们说我有一个 config.json
是这样的:
Let's say I have a config.json
like this:
{
"CustomSection": {
"A": 1,
"B": 2
}
}
我知道我可以使用 IConfiguration
对象来获取特定的设置,即 configuration.Get(CustomSection:A)
,但我可以抓住的整个层次(在任何类型的 - 甚至是原始字符串就可以了)?当我尝试 configuration.Get(CustomSection)
,我收到了空
的结果,所以我觉得这ISN ŧ默认支持的。
I know I can use an IConfiguration
object to get specific settings, i.e., configuration.Get("CustomSection:A")
, but can I grab the whole hierarchy (in any type - even a raw string would be fine)? When I try configuration.Get("CustomSection")
, I get a null
result, so I think this isn't supported by default.
我的用例是抓住一次整个配置字典,而无需抢各个设置 - 某些属性可能并非在编译时已知
My use case is grabbing entire configuration dictionaries at once without having to grab each individual setting - some properties may not be known at compile time.
推荐答案
configuration.Get是获得一个值来得到你需要一节
configuration.Get is for getting a value to get a section you need
IConfiguration mysection = configuration.GetConfigurationSection("SectionKey");
这篇关于检索config.json部分在ASP.NET 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!