I am trying really hard to keep my base classes "clean" while using XML serialization and was wondering if there is any other option. Let me explain first what the situation is.
I have base classes that look like that:
public class Project
{
public string Name { get; set; }
public List<AbstractFlow> Flows { get; set; }
}
public abstract class AbstractFlow
{
public string Name { get; set; }
[XmlArray("Steps")]
[XmlArrayItem("Step", Type = typeof(AbstractSolutionSerializer<AbstractStep>))]
public List<AbstractStep> Steps { get; set; }
}
public abstract class AbstractStep
{
public string Name { get; set; }
public int Length { get; set; }
}
These are inside a library project and the derived classes reside within another library. I use XML serialisation using a custom AbstractProjectSerializer which implements IXmlSerializable and I need to create an intermediate class:
[XmlRoot("ProjectSerializer")]
public sealed class ProjectSerializer
{
public ProjectSerializer(Project project)
{
[XmlElement("Name")]
public string Name { get; set; }
[XmlArray("Flows")]
[XmlArrayItem("Flow", Type = typeof(AbstractProjectSerializer<AbstractFlow>))]
public string List<AbstractFlow> { get; set; }
}
}
I am happy with the intermediate class above however as you notice I needed to go in AbstractFlow and add XML serialization specific attributes. This for me "pollutes" the base classes and ties them with XML serialization. Is there any other way I can achieve what I want?