SpriteDatabaseLoadObjectFromXmlFileT Method |
Load in an XML serialized item from the specified ResourceManager. You will usually make an XML file by
creating an object (as a variable) and using
WriteToXmlFileT(String, T) to
serialize it and save it to a file on your desktop. Then you can drag and drop that file into your project and then use this
LoadObjectFromXmlFile function. You can google XML Serialization for more information.
Namespace:
SpriteLibrary
Assembly:
SpriteLibrary (in SpriteLibrary.dll) Version: 1.0.0.6 (1.0.0.6)
Syntaxpublic static T LoadObjectFromXmlFile<T>(
string XMLResourceToLoad,
ResourceManager MyManager
)
where T : new()
Parameters
- XMLResourceToLoad
- Type: SystemString
The resource item to load. If you would access it like: properties.resources.myFile,
the correct value to put here would be "myFile" - MyManager
- Type: System.ResourcesResourceManager
The resource manager. Usually Properties.Resources.ResourceManager
Type Parameters
- T
- The type of object to load. It could be something as simple as an int, a class, or a list of classes.
Return Value
Type:
TAn object of the value you specified. Or null if it fails.
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 Loads it from a
resource file (one which has been added to Properties.Resources.) The corresponding write function:
WriteToXmlFileT(String, T) writes to a file that is outside of Properties.Resources; the
resources of a program are read-only. Once you write to a file, you can drag the resulting XML into your project
and load it from there. If you want to load from an XML file that is not a resource, use
ReadFromXmlFileT(String)Here is code to create an item and save it to a file.
MyClass MyVariable = new MyClass();
MyVariable.Name = "StoreThis!";
SpriteDatabase.WriteToXmlFile<MyClass>("c:\xml_file.xml", MyClass);
Now that we have an XML file, we drag that file into our project so that it shows up in our Properties.Resources
and then we can use this code to load it.
MyClass MyVariable = SpriteDatabase.LoadObjectFromXmlFile<MyClass>("xml_file",Properties.Resources.ResourceManager);
Console.WriteLine(MyVariable.Name);
See Also