J
Jeti
I try, but i cant serialize Color field when serialiazing class that
contains it! How to do it?
Heres how i do it:
//Class to serialize
public class Colors
{
public Color Back;
public int LineWidth;
public void SetToDefault ()
{
Back = Color.FromArgb (255, 192, 192);
LineWidth = 1;
}
//I try to serialize it like this:
[STAThread]
static void Main()
{
Colors c = new Colors();
c.SetToDefault ();
XmlSerializer serializer = new XmlSerializer(typeof(Colors));
// Create an XmlTextWriter using a FileStream.
Stream fs = new FileStream("options.xml", FileMode.Create);
XmlWriter writer = new XmlTextWriter(fs, new UTF8Encoding());
// Serialize using the XmlTextWriter.
serializer.Serialize(writer, c);
writer.Close();
}
// END OF CODE.
when i look at the generated xml, only integer property serialized ok, but
color property was empty:
<?xml version="1.0" encoding="utf-8"?>
<Colors xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Back />
<LineWidth>1</LineWidth>
</Colors>
Where do i go wrong?
please help!
contains it! How to do it?
Heres how i do it:
//Class to serialize
public class Colors
{
public Color Back;
public int LineWidth;
public void SetToDefault ()
{
Back = Color.FromArgb (255, 192, 192);
LineWidth = 1;
}
//I try to serialize it like this:
[STAThread]
static void Main()
{
Colors c = new Colors();
c.SetToDefault ();
XmlSerializer serializer = new XmlSerializer(typeof(Colors));
// Create an XmlTextWriter using a FileStream.
Stream fs = new FileStream("options.xml", FileMode.Create);
XmlWriter writer = new XmlTextWriter(fs, new UTF8Encoding());
// Serialize using the XmlTextWriter.
serializer.Serialize(writer, c);
writer.Close();
}
// END OF CODE.
when i look at the generated xml, only integer property serialized ok, but
color property was empty:
<?xml version="1.0" encoding="utf-8"?>
<Colors xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Back />
<LineWidth>1</LineWidth>
</Colors>
Where do i go wrong?
please help!