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>