本文整理汇总了C#中ConfigurationBuilder.AddInMemoryCollection方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.AddInMemoryCollection方法的具体用法?C# ConfigurationBuilder.AddInMemoryCollection怎么用?C# ConfigurationBuilder.AddInMemoryCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.AddInMemoryCollection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadAndCombineKeyValuePairsFromDifferentConfigurationProviders
public void LoadAndCombineKeyValuePairsFromDifferentConfigurationProviders()
{
// Arrange
var configurationBuilder = new ConfigurationBuilder();
// Act
configurationBuilder.AddIniFile(_iniConfigFilePath);
configurationBuilder.AddJsonFile(_jsonConfigFilePath);
configurationBuilder.AddXmlFile(_xmlConfigFilePath);
configurationBuilder.AddInMemoryCollection(_memConfigContent);
var config = configurationBuilder.Build();
// Assert
Assert.Equal("IniValue1", config["IniKey1"]);
Assert.Equal("IniValue2", config["IniKey2:IniKey3"]);
Assert.Equal("IniValue3", config["IniKey2:IniKey4"]);
Assert.Equal("IniValue4", config["IniKey2:IniKey5:IniKey6"]);
Assert.Equal("IniValue5", config["CommonKey1:CommonKey2:IniKey7"]);
Assert.Equal("JsonValue1", config["JsonKey1"]);
Assert.Equal("JsonValue2", config["Json.Key2:JsonKey3"]);
Assert.Equal("JsonValue3", config["Json.Key2:Json.Key4"]);
Assert.Equal("JsonValue4", config["Json.Key2:JsonKey5:JsonKey6"]);
Assert.Equal("JsonValue5", config["CommonKey1:CommonKey2:JsonKey7"]);
Assert.Equal("XmlValue1", config["XmlKey1"]);
Assert.Equal("XmlValue2", config["XmlKey2:XmlKey3"]);
Assert.Equal("XmlValue3", config["XmlKey2:XmlKey4"]);
Assert.Equal("XmlValue4", config["XmlKey2:XmlKey5:XmlKey6"]);
Assert.Equal("XmlValue5", config["CommonKey1:CommonKey2:XmlKey7"]);
Assert.Equal("MemValue1", config["MemKey1"]);
Assert.Equal("MemValue2", config["MemKey2:MemKey3"]);
Assert.Equal("MemValue3", config["MemKey2:MemKey4"]);
Assert.Equal("MemValue4", config["MemKey2:MemKey5:MemKey6"]);
Assert.Equal("MemValue5", config["CommonKey1:CommonKey2:MemKey7"]);
Assert.Equal("MemValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
}
示例2: CanOverrideValuesWithNewConfigurationProvider
public void CanOverrideValuesWithNewConfigurationProvider()
{
// Arrange
var configurationBuilder = new ConfigurationBuilder();
// Act & Assert
configurationBuilder.AddIniFile(_iniConfigFilePath);
var config = configurationBuilder.Build();
Assert.Equal("IniValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
configurationBuilder.AddJsonFile(_jsonConfigFilePath);
config = configurationBuilder.Build();
Assert.Equal("JsonValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
configurationBuilder.AddXmlFile(_xmlConfigFilePath);
config = configurationBuilder.Build();
Assert.Equal("XmlValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
configurationBuilder.AddInMemoryCollection(_memConfigContent);
config = configurationBuilder.Build();
Assert.Equal("MemValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
}