I want to make it easy to store lot of data into a XML file. Before I did it with structures and that worked well, but now I want to make use of classes, see my example below. when saving to XML, the subclasses are not saved to the XML.
In the XML file I see a bunch of
<logic>
<logicData xsi:nil="true" />
<logicData xsi:nil="true" />
<logicData xsi:nil="true" />
This is my current code that I use
public class colorProfileSettings
{
public int[] btn_background = new int[16];
public int[] btn_input = new int[16];
public int[] btn_press = new int[16];
}
public class logicData
{
public colorProfileSettings[] colors = new colorProfileSettings[2];
public int configBtnLedTest = 0;
public int configBtnDimPlus = 0;
public int configBtnDimMin = 0;
public int configBtnCleaning = 0;
public int configBtnDayNightToggle = 0;
public int groupBg = 0;
public int groupLedTest = 0;
public int groupDimming = 10;
}
public class ClassConfigData
{
public logicData[] logic = new logicData[100];
public string fileLocName;
}
public ClassConfigData data = new ClassConfigData();
public void WriteXML(string fileLoc)
{
try
{
if (System.IO.File.Exists(fileLoc))
{
XmlSerializer writer = new XmlSerializer(typeof(ClassConfigData));
StreamWriter file = new StreamWriter(@fileLoc);
writer.Serialize(file, data);
file.Close();
}
else
{
throw new ArgumentNullException("Not a valid file selected.");
}
}
catch (Exception e)
{
throw e;
}
}