当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.AddIniFile方法代码示例

本文整理汇总了C#中ConfigurationBuilder.AddIniFile方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.AddIniFile方法的具体用法?C# ConfigurationBuilder.AddIniFile怎么用?C# ConfigurationBuilder.AddIniFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigurationBuilder的用法示例。


在下文中一共展示了ConfigurationBuilder.AddIniFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DifferentConfigSources_Merged_KeysAreSorted

        public void DifferentConfigSources_Merged_KeysAreSorted()
        {
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddJsonFile(_json1ConfigFilePath);
            configurationBuilder.AddIniFile(_iniConfigFilePath);
            configurationBuilder.AddJsonFile(_json2ConfigFilePath);
            configurationBuilder.AddXmlFile(_xmlConfigFilePath);

            var config = configurationBuilder.Build();

            var configurationSection = config.GetSection("address");
            var indexConfigurationSections = configurationSection.GetChildren().ToArray();

            Assert.Equal(8, indexConfigurationSections.Length);
            Assert.Equal("0", indexConfigurationSections[0].Key);
            Assert.Equal("1", indexConfigurationSections[1].Key);
            Assert.Equal("2", indexConfigurationSections[2].Key);
            Assert.Equal("3", indexConfigurationSections[3].Key);
            Assert.Equal("4", indexConfigurationSections[4].Key);
            Assert.Equal("i", indexConfigurationSections[5].Key);
            Assert.Equal("j", indexConfigurationSections[6].Key);
            Assert.Equal("x", indexConfigurationSections[7].Key);

            Assert.Equal("address:0", indexConfigurationSections[0].Path);
            Assert.Equal("address:1", indexConfigurationSections[1].Path);
            Assert.Equal("address:2", indexConfigurationSections[2].Path);
            Assert.Equal("address:3", indexConfigurationSections[3].Path);
            Assert.Equal("address:4", indexConfigurationSections[4].Path);
            Assert.Equal("address:i", indexConfigurationSections[5].Path);
            Assert.Equal("address:j", indexConfigurationSections[6].Path);
            Assert.Equal("address:x", indexConfigurationSections[7].Path);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:32,代码来源:ArrayTests.cs

示例2: 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"]);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:40,代码来源:ConfigurationTests.cs

示例3: CanSetValuesAndReloadValues

        public void CanSetValuesAndReloadValues()
        {
            // Arrange
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddIniFile(_iniConfigFilePath);
            configurationBuilder.AddJsonFile(_jsonConfigFilePath);
            configurationBuilder.AddXmlFile(_xmlConfigFilePath);

            var config = configurationBuilder.Build();

            // Act & Assert
            // Set value
            config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"] = "NewValue";

            // All config sources must be updated
            foreach (var provider in configurationBuilder.Providers)
            {
                Assert.Equal("NewValue",
                    (provider as ConfigurationProvider).Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));
            }

            // Recover values by reloading
            config.Reload();

            Assert.Equal("XmlValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);

            // Set value with indexer
            config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"] = "NewValue";

            // All config sources must be updated
            foreach (var provider in configurationBuilder.Providers)
            {
                Assert.Equal("NewValue",
                    (provider as ConfigurationProvider).Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));
            }

            // Recover values by reloading
            config.Reload();
            Assert.Equal("XmlValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:40,代码来源:ConfigurationTests.cs

示例4: 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"]);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:22,代码来源:ConfigurationTests.cs

示例5: DifferentConfigSources_Merged_WithOverwrites

        public void DifferentConfigSources_Merged_WithOverwrites()
        {
            var builder = new ConfigurationBuilder();

            builder.AddJsonFile(_json1ConfigFilePath);
            builder.AddIniFile(_iniConfigFilePath);
            builder.AddJsonFile(_json2ConfigFilePath);
            builder.AddXmlFile(_xmlConfigFilePath);

            var config = builder.Build();

            Assert.Equal("json_0.0.0.0", config["address:0"]);
            Assert.Equal("xml_1.1.1.1", config["address:1"]);
            Assert.Equal("ini_2.2.2.2", config["address:2"]);
            Assert.Equal("json_3.3.3.3", config["address:3"]);
            Assert.Equal("xml_4.4.4.4", config["address:4"]);
            Assert.Equal("ini_i.i.i.i", config["address:i"]);
            Assert.Equal("json_j.j.j.j", config["address:j"]);
            Assert.Equal("xml_x.x.x.x", config["address:x"]);
        }
开发者ID:pgrudzien12,项目名称:Configuration,代码行数:20,代码来源:ArrayTests.cs

示例6: CanSetValuesAndReloadValues

        public void CanSetValuesAndReloadValues()
        {
            // Arrange
            var builder = new ConfigurationBuilder();
            builder.AddIniFile(_iniConfigFilePath);
            builder.AddJsonFile(_jsonConfigFilePath);
            builder.AddXmlFile(_xmlConfigFilePath);

            var config = builder.Build();

            // Act & Assert
            // Set value with Set() method
            config.Set("CommonKey1:CommonKey2:CommonKey3:CommonKey4", "NewValue");

            // All config sources must be updated
            foreach (var src in builder.Sources)
            {
                Assert.Equal("NewValue",
                    (src as ConfigurationSource).Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));
            }

            // Recover values by reloading
            config.Reload();

            Assert.Equal("XmlValue6", config.Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));

            // Set value with indexer
            config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"] = "NewValue";

            // All config sources must be updated
            foreach (var src in builder.Sources)
            {
                Assert.Equal("NewValue",
                    (src as ConfigurationSource).Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));
            }

            // Recover values by reloading
            config.Reload();
            Assert.Equal("XmlValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
        }
开发者ID:rhwy,项目名称:Configuration,代码行数:40,代码来源:ConfigurationTests.cs


注:本文中的ConfigurationBuilder.AddIniFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。