2 using System.Collections.Generic;
15 private XmlReader reader;
16 private List<String> objectsRead;
20 this.manager = manager;
21 File = manager.
Open( fileName,
false );
23 objectsRead =
new List<string>();
30 objectsRead =
new List<string>();
45 private void ResetFile()
59 File = manager.
Open( fileName,
false );
65 private void BeginReadXml()
72 if ( !reader.IsStartElement(
"State" ) )
throw new ArgumentException(
"File is corrupted or not a save state file." );
77 return (
T)
Load( obj, typeof(
T ), name );
80 public object Load(
object obj, Type type,
string name )
82 if ( objectsRead.Contains( name ) )
96 if ( reader.NodeType == XmlNodeType.None )
97 throw new IOException(
"Error loading object: reader not initialized" );
99 if ( reader.NodeType == XmlNodeType.Element )
103 if ( reader.Name !=
"Object" )
104 throw new XmlException(
"Unexpected element in save state file: " + reader.Name );
106 string objName = reader.GetAttribute(
"Name" );
107 if (
string.IsNullOrEmpty( objName ) )
108 throw new XmlException(
"Unnamed object in save state file" );
110 if ( name == objName )
111 return File.LoadData( reader, type, obj );
113 objectsRead.Add( objName );
116 if ( !reader.IsEmptyElement )
119 else if ( reader.NodeType == XmlNodeType.EndElement )
122 if ( depth < 0 )
throw new InvalidOperationException(
"Error loading object: parse depth < 0" );
126 throw new KeyNotFoundException(
"Object with name " + name +
" could not be found in file " +
File.
Name );
object Load(object obj, Type type, string name)
T Load< T >(T obj, string name)
abstract StorageFile Open(string fileName, bool write)