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


C# Configuration.Add方法代码示例

本文整理汇总了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;
        }
开发者ID:pveller,项目名称:Sitecore.Pathfinder,代码行数:27,代码来源:StartupExtensions.cs

示例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();
        }
开发者ID:bigfont,项目名称:Docs,代码行数:11,代码来源:SettingsController.cs

示例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;
        }
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:16,代码来源:HitCounterService.cs

示例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}!");
        }
开发者ID:bigfont,项目名称:Docs,代码行数:17,代码来源:Program.cs

示例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"));
        }
开发者ID:pveller,项目名称:Sitecore.Pathfinder,代码行数:23,代码来源:ConfigurationServicesTests.cs

示例6: TestConfigurationProvider

 public TestConfigurationProvider()
 {
     Configuration = new Configuration();
     Configuration.Add(new MemoryConfigurationSource());
 }
开发者ID:Nakro,项目名称:Mvc,代码行数:5,代码来源:TestConfigurationProvider.cs


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