本文整理汇总了C#中Microsoft.Framework.ConfigurationModel.Configuration.GetSubKeys方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.GetSubKeys方法的具体用法?C# Configuration.GetSubKeys怎么用?C# Configuration.GetSubKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Framework.ConfigurationModel.Configuration
的用法示例。
在下文中一共展示了Configuration.GetSubKeys方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanGetSubKeys
public void CanGetSubKeys()
{
// Arrange
var dic1 = new Dictionary<string, string>()
{
{"Data:DB1:Connection1", "MemVal1"},
{"Data:DB1:Connection2", "MemVal2"}
};
var dic2 = new Dictionary<string, string>()
{
{"Data:DB2Connection", "MemVal3"}
};
var dic3 = new Dictionary<string, string>()
{
{"DataSource:DB3:Connection", "MemVal4"}
};
var memConfigSrc1 = new MemoryConfigurationSource(dic1);
var memConfigSrc2 = new MemoryConfigurationSource(dic2);
var memConfigSrc3 = new MemoryConfigurationSource(dic3);
var config = new Configuration();
config.AddLoadedSource(memConfigSrc1);
config.AddLoadedSource(memConfigSrc2);
config.AddLoadedSource(memConfigSrc3);
// Act
var configFocusList = config.GetSubKeys("Data");
var subKeysSet = configFocusList.ToDictionary(e => e.Key, e => e.Value);
// Assert
Assert.Equal(2, configFocusList.Count());
Assert.Equal("MemVal1", subKeysSet["DB1"].Get("Connection1"));
Assert.Equal("MemVal2", subKeysSet["DB1"].Get("Connection2"));
Assert.Equal("MemVal3", subKeysSet["DB2Connection"].Get(null));
Assert.False(subKeysSet.ContainsKey("DB3"));
Assert.False(subKeysSet.ContainsKey("Source:DB3"));
}