public static void Deserialize(Puzzle emptyPuzzle, TextReader reader) { SerializationTool tool = new SerializationTool(emptyPuzzle); emptyPuzzle.name = reader.ReadLine(); while (reader.Peek() != -1) { string line = reader.ReadLine(); PuzzleSerializable obj = tool.DeserializePartly(line); if (obj is PuzzleNode) { emptyPuzzle.AddNode(obj as PuzzleNode); } else if (obj is PuzzleEdge) { emptyPuzzle.AddEdge(obj as PuzzleEdge); } else if (obj is PuzzleElement) { emptyPuzzle.AddElement(obj as PuzzleElement); } else if (obj is PuzzleItem) { emptyPuzzle.AddItem(obj as PuzzleItem); } } tool.Final(); }
public PuzzleSerializable DeserializePartly(string str) { string t = GetToken(ref str, ' '); string name = GetToken(ref str, '{'); string content = str.Substring(0, str.Length - 1).Trim(); System.Type typ = typeof(Puzzle).Assembly.GetType(t); object o = System.Activator.CreateInstance(typ); PuzzleSerializable obj = o as PuzzleSerializable; obj.SetName(this, name); pending.Add(obj, content); return(obj); }
public string Serialize(PuzzleSerializable obj) { return(obj.GetType().Name + " " + obj.GetName(this) + " { " + obj.Serialize(this) + " }"); }