本文整理汇总了C#中ConfigManager.Save方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigManager.Save方法的具体用法?C# ConfigManager.Save怎么用?C# ConfigManager.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigManager
的用法示例。
在下文中一共展示了ConfigManager.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestComplexSave
public void TestComplexSave()
{
var baseConfig = CreateTestConfig("configbase.xml");
var userConfig = new Configuration()
{
FilePath = Path.Combine(Path.GetDirectoryName(baseConfig.FilePath), "config.xml"),
Parent = "configbase.xml"
};
baseConfig.ChildConfigurations.Add(userConfig);
userConfig.Parameters.Add(new Parameter()
{
Name = "TestParam",
Value = "uservalue",
ValueComesFromConfiguration = userConfig
});
ConfigManager.SaveConfig(baseConfig);
ConfigManager.SaveConfig(userConfig);
var man = new ConfigManager(userConfig.FilePath);
man.Load();
var param = man.Config.Parameters.FirstOrDefault(p => p.Name == "TestParam");
param.Value = "testnewvalue";
man.Save();
man.Load();
param = man.Config.Parameters.FirstOrDefault(p => p.Name == "TestParam");
Assert.IsTrue(param.Value == "testnewvalue");
}
示例2: TestSaveConfig
public void TestSaveConfig()
{
var provider = new ConfigProviderMock();
var serializer = new ConfigSerializerMock();
var config = new ConfigMock();
var manager = new ConfigManager(provider, serializer);
manager.Save(config);
provider.WrittenConfigs.Should().ContainSingle("the manager should have tried to write the config");
provider.WrittenConfigs[0].Key.Should().Be(config.GetType(), "the written config should be the same as the provided one one");
serializer.Serialized.Should().ContainSingle("the manager should have tried to serialize the config");
serializer.Serialized[0].Key.Should().Be(config.GetType(), "the serialized config type should be the same as the original");
serializer.Serialized[0].Value.Should().BeSameAs(config, "the serialized config should be the same as the provided one");
manager.Save(config);
provider.WrittenConfigs.Should().ContainSingle("the manager should not have tried to re-write an unmodified config");
}