Windows Application
Visual Studio 2005
I am new to C# and have done very little XML or serialization.
My client wishes me to store configuration data in an XML file.
It will look something like this:
<definition>
<hardwaredefinitions>
<hardwaredefinition id="1" name="Configuration Data"
editor="ConfigurationPanel">
<hardwarerowdata>
<row value="Channel position 1" />
<row value="Channel position 2" />
<row value="Channel position 3" />
<row value="Channel position 4" />
</hardwarerowdata>
<itemdata>
<gpsstandby value="true" />
<vehiclevoltageusage value="48" />
</itemdata>
</hardwaredefinition>
</hardwaredefinitions>
</definition>
The elements in the <hardwarerowdatanode (<row..../>) will be
displayed in a data grid. The elements in the <itemdatanode
(<gpsstandby etc.) will be used to populate a check box and a text box
on the form.
This data may be changed and saved back to the XML file. I'd like to
use the built-in methods to serialize it, but it barfs because the
<row.../nodes are being stored in an array and it throws the
following exception:
..HardwareDefinitionRow cannot be serialized because it does not have a
parameterless constructor.
HardwareDefinitionRow is declared thus:
public HardwareDefinitionRow[] HardwareDefinitionRows
{
get { return m_rows; }
}
public class HardwareDefinitionRow
{
public HardwareDefinitionRow(int i)
{
index = i;
}
public int Index
{
get { return index; }
}
public string HardwareDefinition
{
get { return hardwaredefinition; }
set { hardwaredefinition = value; }
}
private int index;
private string hardwaredefinition;
}
HardwareDefinitionRow[] m_rows;
Anyone any idea about how I can crack this?
Thanks
Edward