SpriteDatabaseReadFromXmlFileT Method |
Reads an object instance from an XML file.
Object type must have a parameterless constructor.
Namespace:
SpriteLibrary
Assembly:
SpriteLibrary (in SpriteLibrary.dll) Version: 1.0.0.6 (1.0.0.6)
Syntaxpublic static T ReadFromXmlFile<T>(
string filePath
)
where T : new()
Parameters
- filePath
- Type: SystemString
The file path to read the object instance from.
Type Parameters
- T
- The type of object to read from the file.
Return Value
Type:
TReturns a new instance of the object read from the XML file.
Examples
XML Serialization takes an object (a class, a variable, or whatever) and will store any public values in XML.
You can choose to save the resulting XML as a string, or to save it to a file. This function
reads in a file that probably has been written by
WriteToXmlFileT(String, T).
MyClass MyVariable = new MyClass();
MyVariable.Name = "StoreThis!";
SpriteDatabase.WriteToXmlFile<MyClass>("c:\xml_file.xml", MyClass);
Now that we have an XML file, we can use this code to load it.
MyClass MyVariable = SpriteDatabase.ReadFromXmlFile<MyClass>("c:\xml_file.xml");
Console.WriteLine(MyVariable.Name);
See Also