I am absolutely baffled as to why this won't work. My code will write values directly to the XML file however for some odd reason I can't seem to take the values from said file and "import" them into there individual respective variables. Consider the following:
public class SaveLoadConfiguration
{
public int height { get; set; }
public int width { get; set; }
public int frameratecap { get; set; }
public bool cap { get; set; }
public SaveLoadConfiguration LoadGameData(string fileName) // SavedGameData.xml
{
XmlSerializer serializer = new XmlSerializer(typeof(SaveLoadConfiguration));
StreamReader LoadGameData = new StreamReader(fileName);
return (SaveLoadConfiguration)serializer.Deserialize(LoadGameData);
}
}
What should happen here is when I call the LoadGameData method as a property from SaveLoadConfiguration class it should simply take the XML file contents ( height, width, frameratecap , and cap variables are all written to the XML file in there respective orders ) and send them to there respective variables. However, this is simply not working. When the code compiles, regardless of what these variables in the XML file are, or what has been listed on those files on a previous state, or anything really, it prints 0 to the screen if I print anyone of those variables ( after loading them using the LoadGameData method which also should set the XML file contents to their individual respective variable correlation such as height, width, frameratecap and cap etc... ). I checked the entirety of the XML documentation, I just simply cannot fathom why it is doing it. I have suspicion that perhaps one of said XML file variables are not being setted to their respective variables within the code and thus printing it no matter the result is 0. I don't really know. If anyone can help it would be appreciated.
XML file: ( contents within it notably the height variable has already been set using a write method that writes directly to the XML file as intended )
<SaveLoadConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<height>1080</height>
<width>0</width>
<frameratecap>0</frameratecap>
<cap>false</cap>
</SaveLoadConfiguration>