0

I am trying to serialize bunch of objects. I have designed a smaller sample code to debug the issue, in which I want to save the color of custom link i.e. CustomLink(Color.Blue)

Below is the main class-

public class Factory
{
    CustomLink customLink = new CustomLink(Color.Blue); // This color is not getting serialized

    static Type[] xMLSerializationTypes = { typeof(CustomLink) };
    static void Main(string[] args)
    {
        Factory factory = new Factory();
        XmlSerializer serializer = new XmlSerializer(typeof(Factory), xMLSerializationTypes);
        TextWriter textWriter = new StreamWriter(@"D:\test.xml");
        serializer.Serialize(textWriter, factory);
        textWriter.Close();
    }

    public CustomLink CustomLink
    {
        set { customLink = value; }
        get { return customLink; }
    }
}

Following are the remaining classes-

public class CustomLink : Link
{
    public CustomLink() { }
    public CustomLink(Color color)
    {
        GraphicProperty.Color = color;
    }
}
public class Link
{
    GraphicProperty graphicProperty = new GraphicProperty();
    public GraphicProperty GraphicProperty
    {
        set { graphicProperty = value; }
        get { return graphicProperty; }
    }
}
public class GraphicProperty
{
    Color color;
    public GraphicProperty() { }
    public Color Color
    {
        set { color = value; }
        get { return color; }
    }
}

Below is the ouput, which doesnt contain any color information-

<?xml version="1.0" encoding="utf-8"?>
<Factory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CustomLink>
    <GraphicProperty>
      <Color />
    </GraphicProperty>
  </CustomLink>
</Factory>
Christos
  • 53,228
  • 8
  • 76
  • 108
ravi
  • 6,140
  • 18
  • 77
  • 154
  • 2
    Related: [Most elegant xml serialization of Color structure](http://stackoverflow.com/q/3280362/74757) – Cᴏʀʏ Aug 11 '14 at 15:10
  • @Cory: Thank you for pointing me out to correct reference. This is pretty amazing to know that Color can't be serialize in normal way. :) – ravi Aug 11 '14 at 15:46

0 Answers0