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


C# AppSettings.SetValue方法代码示例

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


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

示例1: And_settings_file_does_not_exist_it_should_be_created

        public void And_settings_file_does_not_exist_it_should_be_created()
        {
            var fileName = Guid.NewGuid() + ".config";
            var fullPathToConfigurationFile = TestHelpers.GetFullPathToConfigurationFile(fileName);

            try
            {
                Assert.IsFalse(System.IO.File.Exists(fullPathToConfigurationFile));

                var settings = new AppSettings(fullPathToConfigurationFile, FileOption.None);

                settings.SetValue("string", "a");
                settings.SetValue<int>("int", 1);
                settings.SetValue<int?>("nullableint", null);

                settings.Save();

                Assert.IsTrue(System.IO.File.Exists(fullPathToConfigurationFile));
                Assert.IsTrue(settings.FileExists);
            }
            finally
            {
                TestHelpers.DeleteIfExists(fullPathToConfigurationFile);
            }
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:25,代码来源:When_saving_settings.cs

示例2: And_setting_exists_Then_existing_setting_should_be_replaced

        public void And_setting_exists_Then_existing_setting_should_be_replaced()
        {
            var settings = new AppSettings("NonExistingFile", FileOption.None);
            var settingName = "setting";

            // Original value
            settings.SetValue(settingName, "a");
            Assert.AreEqual("a", settings.GetValue(settingName));

            // Save with different value
            settings.SetValue(settingName, "b");

            Assert.AreEqual("b", settings.GetValue(settingName));
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:14,代码来源:When_updating_string_value.cs

示例3: And_value_is_null_Then_update_should_succeed

        public void And_value_is_null_Then_update_should_succeed()
        {
            var settings = new AppSettings("NonExistingFile", FileOption.None);

            settings.SetValue("setting", null);

            Assert.AreEqual(null, settings.GetValue("setting"));
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:8,代码来源:When_updating_string_value.cs

示例4: And_setting_does_not_exist_Then_setting_should_be_stored

        public void And_setting_does_not_exist_Then_setting_should_be_stored()
        {
            var settings = new AppSettings("NonExistingFile", FileOption.None);

            settings.SetValue("setting", "a");

            Assert.AreEqual("a", settings.GetValue("setting"));
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:8,代码来源:When_updating_string_value.cs

示例5: And_custom_conversion_function_is_specified_value_it_returns_should_be_used

        public void And_custom_conversion_function_is_specified_value_it_returns_should_be_used()
        {
            var settings = new AppSettings("NonExistingFile", FileOption.None);

            settings.SetValue<int>("setting", 1, (settingName, rawValue) => "a");

            Assert.AreEqual("a", settings.GetValue("setting"));
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:8,代码来源:When_updating_generic_value.cs

示例6: Should_succeed

        public void Should_succeed()
        {
            var originalFile = SimpleConfig.AbsolutePathToConfigFile;
            var tempFile = TestHelpers.CreateCopyOfFile(originalFile);

            try
            {
                var settings = new AppSettings(tempFile, FileOption.FileMustExist);

                // Read existing settings
                settings.GetValue(SimpleConfig.NonEmptyStringValue);
                settings.GetValue<int>(SimpleConfig.IntValue);
                settings.GetValue<int?>(SimpleConfig.EmptyIntValue);
                settings.GetValue<double>(SimpleConfig.DoubleValue);

                // Modify settings
                settings.SetValue(SimpleConfig.NonEmptyStringValue, "nonEmptyValue");
                settings.SetValue<int>(SimpleConfig.IntValue, int.MinValue);
                settings.SetValue<int?>(SimpleConfig.EmptyIntValue, 1);
                settings.SetConnectionString("MyDatabase", "db");

                settings.Save();

                var otherSettings = new AppSettings(tempFile, FileOption.FileMustExist);
                var nonEmptyString = otherSettings.GetValue(SimpleConfig.NonEmptyStringValue);
                var intValue = otherSettings.GetValue<int>(SimpleConfig.IntValue);
                var emptyIntValue = otherSettings.GetValue<int?>(SimpleConfig.EmptyIntValue);
                var doubleValue = otherSettings.GetValue<double>(SimpleConfig.DoubleValue);

                Assert.AreEqual("nonEmptyValue", nonEmptyString);
                Assert.AreEqual(int.MinValue, intValue);
                Assert.AreEqual(1, emptyIntValue);
                Assert.AreEqual(1.1d, doubleValue);
            }
            finally
            {
                TestHelpers.DeleteIfExists(tempFile);
            }
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:39,代码来源:Read_existing_settings_modify_save_and_read_again.cs

示例7: And_custom_IFromatProvider_is_specified_it_should_be_used

        public void And_custom_IFromatProvider_is_specified_it_should_be_used()
        {
            var settings = new AppSettings("NonExistingFile", FileOption.None);
            var formatProvider = CultureInfo.GetCultureInfo("fi-FI");

            settings.SetValue<double>("setting", 1.1, formatProvider);

            Assert.AreEqual(1.1d, settings.GetValue<double>("setting", formatProvider));

            // Since the value was stored using fi-FI locale then string value
            // should have value of 1,1 (comma instead of dot)
            Assert.AreEqual("1,1", settings.GetValue("setting"));
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:13,代码来源:When_updating_generic_value.cs

示例8: 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("NonExistingFile", FileOption.None);

            var functionCalled = false;
            settings.SetValue<int>("setting", 1, (settingName, rawValue) =>
                {
                    functionCalled = true;
                    return rawValue.ToString();
                });

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

示例9: Then_values_should_be_saved_using_invariant_culture

        public void Then_values_should_be_saved_using_invariant_culture()
        {
            var originalFile = SimpleConfig.AbsolutePathToConfigFile;
            var tempFile = TestHelpers.CreateCopyOfFile(originalFile);

            try
            {
                var settings = new AppSettings(tempFile, FileOption.FileMustExist);
                settings.SetValue<double>("OtherDouble", 1.1);

                settings.Save();

                var otherSettings = new AppSettings(tempFile, FileOption.FileMustExist);
                var value = otherSettings.GetValue<double>("OtherDouble");

                Assert.AreEqual(1.1d, value);
            }
            finally
            {
                TestHelpers.DeleteIfExists(tempFile);
            }
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:22,代码来源:When_saving_settings.cs

示例10: Then_existing_setting_is_overwritten

        public void Then_existing_setting_is_overwritten()
        {
            // Initialize with value "a"
            var settings = new AppSettings("filename", FileOption.None);
            settings.SetValue("NonEmptyStringValue", "a");

            // Overwrite a with b
            var mySettings = new SettingsWithPublicGetters("b", 1, null);

            settings.ReadFrom(mySettings);

            Assert.AreEqual("b", settings.GetValue("NonEmptyStringValue"));
        }
开发者ID:tparvi,项目名称:appsettings,代码行数:13,代码来源:When_reading_from_public_properties.cs


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