本文整理汇总了C#中Config.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Config.ContainsKey方法的具体用法?C# Config.ContainsKey怎么用?C# Config.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config
的用法示例。
在下文中一共展示了Config.ContainsKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateChangeSet
public static ChangeSet GenerateChangeSet(Config oldConfig, Config newConfig)
{
var cs = new ChangeSet();
foreach (var n in oldConfig)
{
var oldKey = n.Key;
if (newConfig.ContainsKey(oldKey))
{
var newNode = newConfig[oldKey];
if (n.Value != newNode)
{
cs.Add(new ConfigChange() { Type = ChangeType.Modified, Key = oldKey, Old = n.Value, New = newNode });
}
}
else
{
cs.Add(new ConfigChange() { Type = ChangeType.Removed, Key = oldKey, Old = n.Value, New = null });
}
}
foreach (var n in newConfig)
{
var newKey = n.Key;
if (!oldConfig.ContainsKey(newKey))
{
cs.Add(new ConfigChange() { Type = ChangeType.Added, Key = newKey, Old = null, New = newConfig[newKey] });
}
}
return cs;
}
示例2: Config_Parse
public void Config_Parse()
{
var config = new Config();
var configString = @"
# Hello world
#!type = ""string""
Hello.World = ""True""
";
var stream = new MemoryStream(Encoding.UTF8.GetBytes(configString));
ConfigLoader.Load(config, stream);
Assert.IsTrue(config.ContainsKey("Hello.World"), "Config doesn't contain key");
var node = config["Hello.World"];
Assert.AreEqual("True", node.Value, "Unexpected value in key");
Assert.AreEqual("string", node.Metadata["type"], "Type invalid");
Assert.AreEqual(" Hello world", node.Comments[0], "Comment incorrect");
}
示例3: test_contains_key
public void test_contains_key()
{
dynamic config = new Config(JsonConfig);
Assert.That(config.ContainsKey("theEnvironment"), Is.True);
Assert.That(config.ContainsKey("DoesNotExist"), Is.False);
}