【发布时间】:2020-08-30 03:40:20
【问题描述】:
我有:
IConfiguration cfg;
string key;
当密钥具有 'null' 值时,我必须检测 key 是否存在于 cfg 中。
我知道钥匙在里面,我用调试器看到它,但我需要一种方法来检测它。
我认为cfg.GetSection(key).Exists() 会返回 True。
但它总是返回 False。
根据文档,cfg.GetSection(key)从不返回 null,即使 key 不存在,所以它没有帮助。
【问题讨论】:
-
你不是已经问过同样的How to know if a Key exists on IConfiguration了吗?
-
我确实问过 - 但答案是使用
Exists()方法 - 但如果值为 null 则不起作用
标签: c# .net .net-core configuration