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