You could try saving it as a serialized object either XML or binary. You would need to mark the class's that will be serialized with the attribute. Generic collections are already serializable.
[Serializable]
public class Node
{
...
}
[Serializable]
public class Trie
{
...
}
XML Save
var trie = new Trie();
using (var fs = new System.IO.FileStream("path", FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
Type objType = typeof (Trie);
var xmls = new XmlSerializer(objType);
xmls.Serialize(fs, trie);
}
XML Load
XmlSerializer xmls = new XmlSerializer(typeof(Trie));
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
return xmls.Deserialize(fs) as Trie;
Binary Save
var trie = new Trie();
using (var fs = new System.IO.FileStream("path", FileMode.CreateNew,
FileAccess.Write))
{
var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bf.Serialize(fs, trie);
}
Binary Load
using (var fs = new FileStream("Path", FileMode.Open, FileAccess.Read))
{
var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
return bf.Deserialize(fs) as Trie;
}