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


C# ConfigManager.Get方法代码示例

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


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

示例1: TestGetConfig

        public void TestGetConfig()
        {
            var provider = new ConfigProviderMock();
            var serializer = new ConfigSerializerMock();
            var manager = new ConfigManager(provider, serializer);

            manager.Get<ConfigMock>();
            provider.ReadConfigs.Should().ContainSingle("the manager should have tried to read the config");
            provider.ReadConfigs[0].Should().Be(typeof(ConfigMock), "the read config should be of the requested type");
            provider.WrittenConfigs.Should().BeEmpty("the manager should not have tried to write the config");
            serializer.Serialized.Should().BeEmpty("the manager should not have tried to serialize the config");
            serializer.Deserialized.Should().ContainSingle("the manager should have tried to deserialize the read config");
            serializer.Deserialized[0].Key.Should().Be(typeof(ConfigMock), "the deserialized config should be the same as the read one");

            manager.Get<ConfigMock>();
            provider.ReadConfigs.Should().ContainSingle("the manager should not have tried to reread the config");
            provider.WrittenConfigs.Should().BeEmpty("the manager should not have tried to write the config when returning it a second time");
            serializer.Serialized.Should().BeEmpty("the manager should not have tried to serialize the config when returning it a second time");
            serializer.Deserialized.Should().ContainSingle("the manager should not have tried to re-deserialize the config");
        }
开发者ID:MarinAtanasov,项目名称:AppBrix.NetCore,代码行数:20,代码来源:ConfigManagerTests.cs

示例2: Main

        internal static void Main(string[] args)
        {
            var stopwatch = Stopwatch.StartNew();
            var configManager = new ConfigManager(new FilesConfigProvider("./Config", "json"), new JsonConfigSerializer());
            if (configManager.Get<AppConfig>().Modules.Count == 0)
                configManager.Get<AppConfig>().Modules.Add(ModuleConfigElement.Create<ConfigInitializerModule>());

            var app = App.Create(configManager);
            app.Start();
            try
            {
                Program.Run(app);
            }
            catch (Exception ex)
            {
                app.GetLog().Error("The application has stopped because of an error!", ex);
            }
            finally
            {
                app.Stop();
                Console.WriteLine("Executed in: {0} seconds.", stopwatch.Elapsed.TotalSeconds);
            }
        }
开发者ID:MarinAtanasov,项目名称:AppBrix.NetCore,代码行数:23,代码来源:Program.cs

示例3: WithEntropy_SaveWithEntropy_LoadWithEntropy_LoadedValueIsSame

        private void WithEntropy_SaveWithEntropy_LoadWithEntropy_LoadedValueIsSame()
        {
            var entropy = new byte[] {1, 2, 3, 4, 5, 6};
            var configManager = new ConfigManager()
                .AtApplicationFolder()
                .WithEntropy(entropy)
                .Set("MyAge", 29)
                .Save();

            configManager = new ConfigManager()
                .AtApplicationFolder()
                .WithEntropy(entropy)
                .Load();

            var myAge = configManager.Get<int>("MyAge");

            Assert.Equal(29, myAge);
        }
开发者ID:alex-erygin,项目名称:safe-config,代码行数:18,代码来源:ConfigManagerTests.cs

示例4: TestSaveAllConfigs

        public void TestSaveAllConfigs()
        {
            var provider = new ConfigProviderMock();
            var serializer = new ConfigSerializerMock();
            var manager = new ConfigManager(provider, serializer);

            manager.SaveAll();
            provider.ReadConfigs.Should().BeEmpty("the manager should have not tried to read any configs");
            provider.WrittenConfigs.Should().BeEmpty("the manager should not have tried to write any configs");
            serializer.Serialized.Should().BeEmpty("the manager should not have tried to serialize any configs");
            serializer.Deserialized.Should().BeEmpty("the manager should have tried to deserialize any configs");

            manager.Get<ConfigMock>();
            manager.SaveAll();
            provider.WrittenConfigs.Should().ContainSingle("the manager should have tried to write the config");
            provider.WrittenConfigs[0].Key.Should().Be(typeof(ConfigMock), "the written config should be the same as the requested one");
            serializer.Serialized.Should().ContainSingle("the manager should have tried to serialize the config");
            serializer.Serialized[0].Key.Should().Be(typeof(ConfigMock), "the serialized config should be the same as the requested one");
            
            manager.SaveAll();
            provider.WrittenConfigs.Should().ContainSingle("the manager should not have tried to re-write an unmodified config");
        }
开发者ID:MarinAtanasov,项目名称:AppBrix.NetCore,代码行数:22,代码来源:ConfigManagerTests.cs


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