本文整理汇总了C#中Microsoft.Framework.ConfigurationModel.Configuration.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.Add方法的具体用法?C# Configuration.Add怎么用?C# Configuration.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Framework.ConfigurationModel.Configuration
的用法示例。
在下文中一共展示了Configuration.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Index
public IActionResult Index()
{
var config = new Configuration();
config.Add(new EfSettingConfigurationSource(_dbContext));
ViewBag.TwitterApiKey = config["TwitterApiKey"];
ViewBag.FacebookApiKey = config["FacebookApiKey"];
ViewBag.GoogleAnalyticsKey = config["GoogleAnalyticsKey"];
return View();
}
示例3: 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;
}
示例4: Main
public void Main(string[] args)
{
var configuration = new Configuration();
Console.WriteLine("Initial Config Sources: " + configuration.Sources.Count());
var defaultSettings = new MemoryConfigurationSource();
defaultSettings.Set("username", "Guest");
configuration.Add(defaultSettings);
Console.WriteLine("Added Memory Source. Sources: " + configuration.Sources.Count());
configuration.AddCommandLine(args);
Console.WriteLine("Added Command Line Source. Sources: " + configuration.Sources.Count());
string username = configuration.Get("username");
Console.WriteLine($"Hello, {username}!");
}
示例5: AddCommandLineTest
public void AddCommandLineTest()
{
var configuration = new Microsoft.Framework.ConfigurationModel.Configuration();
configuration.Add(new MemoryConfigurationSource());
var configurationService = new ConfigurationService(configuration);
IEnumerable<string> args = new List<string>()
{
"build", "/param1=1", "/param2=2 2", "/param3", "3", "posarg1", "--switch1", "true", "/param4", "4 4"
};
configurationService.AddCommandLine(configuration, args);
Assert.AreEqual("build", configuration.Get("arg0"));
Assert.AreEqual("posarg1", configuration.Get("arg1"));
Assert.AreEqual("1", configuration.Get("param1"));
Assert.AreEqual("2 2", configuration.Get("param2"));
Assert.AreEqual("3", configuration.Get("param3"));
Assert.AreEqual("4 4", configuration.Get("param4"));
Assert.AreEqual("true", configuration.Get("switch1"));
}
示例6: TestConfigurationProvider
public TestConfigurationProvider()
{
Configuration = new Configuration();
Configuration.Add(new MemoryConfigurationSource());
}