Handle KV1 root names
masterKV1 files require a single named root object.
- When reading: The name is stored in
KVDocument.Name. - When writing: Pass a
KVDocument(which contains the name) or pass a bareKVObjectalong with a string representing the root name.
var root = KVObject.ListCollection();
root.Add("Developer", "Valve Software");
root.Add("Name", "Dota 2");
var kv = KVSerializer.Create(KVSerializationFormat.KeyValues1Text);
using var stream = File.OpenWrite("file.vdf");
// Option 1: Serialize bare object with a root name
kv.Serialize(stream, root, "root object name");
// Option 2: Wrap in a KVDocument
var doc = new KVDocument(null, "root object name", root);
kv.Serialize(stream, doc);