public object restoreObject(XmlReader xmlReader) { Object lastReadObject = null; try { while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { if (xmlReader.Name.Equals(SAVEABLE_ELEMENT)) { int version = 0; String versionStr = xmlReader.GetAttribute(VERSION_ATTIBUTE); if (versionStr != null) { version = NumberParser.ParseInt(versionStr); } ObjectIdentifier objectId = ObjectIdentifierFactory.CreateObjectIdentifier(NumberParser.ParseLong(xmlReader.GetAttribute(ID_ATTIBUTE)), xmlReader.GetAttribute(TYPE_ATTRIBUTE), typeFinder); loadControl.startDefiningObject(objectId, version); //If the element is empty do not bother to loop looking for elements. if (!xmlReader.IsEmptyElement) { while (!(xmlReader.Name == SAVEABLE_ELEMENT && xmlReader.NodeType == XmlNodeType.EndElement) && xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { valueReaders[xmlReader.Name].readValue(loadControl, xmlReader); } } } lastReadObject = loadControl.createCurrentObject(); } } } } finally { loadControl.reset(); } return(lastReadObject); }
public object restoreObject(JsonReader reader) { Object lastReadObject = null; try { //Read array reader.Read(); if (reader.TokenType != JsonToken.StartArray) { throw new InvalidOperationException("Saveable Json Files must be an array of objects."); } bool keepReading = true; while (keepReading && reader.Read()) { Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value); switch (reader.TokenType) { case JsonToken.StartObject: lastReadObject = readSaveable(reader); break; case JsonToken.EndArray: keepReading = false; break; } } } finally { loadControl.reset(); } return(lastReadObject); }