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


C# AppSettings.GetOptionalValue方法代码示例

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


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

示例1: And_setting_exists_then_its_value_is_returned

        public void And_setting_exists_then_its_value_is_returned()
        {
            var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);

            var value = settings.GetOptionalValue(SimpleConfig.NonEmptyStringValue, null);

            Assert.AreEqual("abc", value);
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:8,代码来源:When_Getting_Optional_String_Value.cs

示例2: And_setting_does_not_exist_then_default_value_is_returned

        public void And_setting_does_not_exist_then_default_value_is_returned()
        {
            var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);

            var defaultValue = "default value";
            var value = settings.GetOptionalValue("NonExistingParameter", defaultValue);

            Assert.AreEqual(defaultValue, value);
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:9,代码来源:When_Getting_Optional_String_Value.cs

示例3: And_file_does_not_exist_default_value_is_returned

        public void And_file_does_not_exist_default_value_is_returned()
        {
            var settings = new AppSettings("NonExistingSettingsFile.config", FileOption.None);

            var defaultValue = 100;
            var value = settings.GetOptionalValue<int>("NonExistingSetting", defaultValue);

            Assert.AreEqual(defaultValue, value);
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:9,代码来源:When_Getting_Optional_Value.cs

示例4: And_custom_conversion_function_is_specified_it_should_be_used

        public void And_custom_conversion_function_is_specified_it_should_be_used()
        {
            var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);
            var functionCalled = false;

            settings.GetOptionalValue<int>(SimpleConfig.IntValue, 100, (setting, settingValue) => { functionCalled = true; return 0; });

            Assert.IsTrue(functionCalled);
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:9,代码来源:When_Getting_Optional_Value.cs

示例5: And_custom_conversion_function_is_specified_its_value_should_be_returned

        public void And_custom_conversion_function_is_specified_its_value_should_be_returned()
        {
            var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);
            var expectedValue = 100;

            var value = settings.GetOptionalValue<int>(SimpleConfig.IntValue, expectedValue, (setting, settingValue) => expectedValue);

            Assert.AreEqual(expectedValue, value);
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:9,代码来源:When_Getting_Optional_Value.cs

示例6: And_AppSetting_section_does_not_exist_default_value_is_returned

        public void And_AppSetting_section_does_not_exist_default_value_is_returned()
        {
            var settings = new AppSettings(NoAppSettingsConfig.AbsolutePathToConfigFile);

            var defaultValue = 100;
            var value = settings.GetOptionalValue<int>("NonExistingSetting", defaultValue);

            Assert.AreEqual(defaultValue, value);
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:9,代码来源:When_Getting_Optional_Value.cs

示例7: And_CultureInfo_is_specified_it_should_be_used

        public void And_CultureInfo_is_specified_it_should_be_used()
        {
            var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);
            var expectedValue = 1.1;
            var anyDefaultValue = 0.0;

            var value = settings.GetOptionalValue<double>(SimpleConfig.DoubleWithFinnishLocale, anyDefaultValue, CultureInfo.GetCultureInfo("fi-FI"));

            Assert.AreEqual(expectedValue, value);
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:10,代码来源:When_Getting_Optional_Value.cs

示例8: And_value_cannot_be_converted_exception_is_thrown

        public void And_value_cannot_be_converted_exception_is_thrown()
        {
            var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);

            Assert.Throws<AppSettingException>(() => settings.GetOptionalValue<decimal>(SimpleConfig.NonEmptyStringValue, 1.1m));
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:6,代码来源:When_Getting_Optional_Value.cs

示例9: And_setting_exists_then_its_value_is_returned

        public void And_setting_exists_then_its_value_is_returned()
        {
            var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);

            var anyDefaultValue = 100;
            var value = settings.GetOptionalValue<int>(SimpleConfig.IntValue, anyDefaultValue);

            Assert.AreEqual(1, value);
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:9,代码来源:When_Getting_Optional_Value.cs


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