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


C# Configuration.Set方法代码示例

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


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

示例1: RegisterConfiguration

        public static IConfigurationSourceRoot RegisterConfiguration([NotNull] this Startup startup, [NotNull] string toolsDirectory, [NotNull] string projectDirectory, ConfigurationOptions options)
        {
            var configuration = new Microsoft.Framework.ConfigurationModel.Configuration();
            configuration.Add(new MemoryConfigurationSource());

            configuration.Set(Constants.Configuration.ToolsDirectory, toolsDirectory);
            configuration.Set(Constants.Configuration.ProjectDirectory, projectDirectory);
            configuration.Set(Constants.Configuration.SystemConfigFileName, "scconfig.json");

            var configurationService = new ConfigurationService(configuration);

            if ((options & ConfigurationOptions.DoNotLoadConfig) != ConfigurationOptions.DoNotLoadConfig)
            {
                try
                {                       
                    configurationService.Load(options);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    return null;
                }
            }

            return configuration;
        }
开发者ID:pveller,项目名称:Sitecore.Pathfinder,代码行数:27,代码来源:StartupExtensions.cs

示例2: UpdateCount

        public int UpdateCount()
        {
            var config = new Configuration();
            config.Add(new MemoryConfigurationSource());
            var KEY = "count";
            var count = 1;

            var value = config.Get(KEY);
            if (value != null)
            {
                count = int.Parse(value);
                count++;
            }
            config.Set(KEY, count.ToString());
            return count;
        }
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:16,代码来源:HitCounterService.cs

示例3: SettingValueUpdatesAllConfigurationSources

        public void SettingValueUpdatesAllConfigurationSources()
        {
            // Arrange
            var dict = new Dictionary<string, string>()
                {
                    {"Key1", "Value1"},
                    {"Key2", "Value2"}
                };
            var memConfigSrc1 = new MemoryConfigurationSource(dict);
            var memConfigSrc2 = new MemoryConfigurationSource(dict);
            var memConfigSrc3 = new MemoryConfigurationSource(dict);

            var config = new Configuration();
            config.AddLoadedSource(memConfigSrc1);
            config.AddLoadedSource(memConfigSrc2);
            config.AddLoadedSource(memConfigSrc3);

            // Act
            config.Set("Key1", "NewValue1");
            config["Key2"] = "NewValue2";

            // Assert
            Assert.Equal("NewValue1", config.Get("Key1"));
            Assert.Equal("NewValue1", memConfigSrc1.Get("Key1"));
            Assert.Equal("NewValue1", memConfigSrc2.Get("Key1"));
            Assert.Equal("NewValue1", memConfigSrc3.Get("Key1"));
            Assert.Equal("NewValue2", config["Key2"]);
            Assert.Equal("NewValue2", memConfigSrc1.Get("Key2"));
            Assert.Equal("NewValue2", memConfigSrc2.Get("Key2"));
            Assert.Equal("NewValue2", memConfigSrc3.Get("Key2"));
        }
开发者ID:perezgb,项目名称:Configuration,代码行数:31,代码来源:ConfigurationTest.cs


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