void Merge(YamlMapping map) { foreach (var entry in map) { if (!ContainsKey(entry.Key)) { Add(entry.Key, entry.Value); } } }
private void MappingToYaml(YamlMapping node, string pres, Context c) { var tag = TagToYaml(node, "!!map"); if (node.Count > 0) { if (tag != "" || c == Context.Map) { WriteLine(tag); c = Context.Normal; } string press = pres + indent; // Serialize by keeping an order on the keys (default true) in order to have a more predictive output for // versionning, comparison, editing...etc. var it = config.OrderMappingKeyByName ? (IEnumerable <KeyValuePair <YamlNode, YamlNode> >)node.OrderBy(OnKeySelector) : node; foreach (var item in it) { if (c != Context.List) { Write(pres); } c = Context.Normal; if (WriteImplicitKeyIfPossible(item.Key, press, Context.NoBreak)) { Write(": "); NodeToYaml(item.Value, press, Context.Map); } else { // explicit key Write("? "); NodeToYaml(item.Key, press, Context.List); Write(pres); Write(": "); NodeToYaml(item.Value, press, Context.List); } } } else { if (tag != "" && tag != "!!map") { Write(tag + " "); } Write("{}"); if (c != Context.NoBreak) { WriteLine(); } } }