Based on a certain flag, I need to switch between the default XmlSerialization deserializer and IXmlSerialization interface implementation. How can I do that? E.g.
public class SomeClass: IXmlSerializer
{
//Other primitive and complex properties
//...
//
//Another issue is - What would be the best way to inject depencencies?
SomeClass(ISomeDepedency dependency)
{
}
public ReadXml(XmlReader rdr)
{
var someValues = dependency.GetSomeValuesFromDBForCustomSerializtion();
}
}
public static void Main(string[] args)
{
//This is filled out
XmlReader rdr = null;
XmlSerializer serializer = new XmlSerializer(typeof(SomeClass));
if(useCustomSerializer)
{
//use IXmlSerializer implemenation
}
else
{
//use Default Serializer
}
var someClass= serializer.Deserialize(rdr);
}
I know that IXmlSerializer implementation is all or nothing. Is there any way to achieve this?