I have the following method
public static void SerializeToXMLFile(Object obj,Type type, string fileName)
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = new XmlSerializer(type);
TextWriter tw = new StreamWriter(fileName);
serializer.Serialize(tw, obj, ns);
tw.Close();
}
The problem is that notice in the line of code that obj will be serialized as an object.
serializer.Serialize(tw, obj, ns);
What I would prefer is that it is serlized as its relevant type for example:
serializer.Serialize(tw, (type) obj, ns);
How is this done? To get the type conversion to work from a dynamic variable?