本文整理汇总了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;
}
示例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;
}
示例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"));
}