I have a method, serializetoxml
, that accepts an object of type obj1
as its parameter:
class Program
{
static void Main(string[] args)
{
obj1 myobj = new obj1();
serializetoxml(myobj);
}
}
public class obj1
{
public string a { get; set; }
public int b { get; set; }
public bool c { get; set; }
}
public static void serializetoxml(obj1 myobj)
{
XmlSerializer myserializer = new XmlSerializer(typeof(obj1));
TextWriter mywriter = new StreamWriter("C:\\my.xml");
myserializer.Serialize(mywriter, myobj);
mywriter.Close();
}
Now I have a class, obj2
, that I want to pass as its parameter
public class obj2
{
public int a { get; set; }
public bool b { get; set; }
public List<string> c { get; set; }
}
How do I reuse the serializetoxml
method to be able to accept another type of parameter, so that I will not write the same method again and change the typeof to obj2
?
obj2 myobj = new obj2();
serializetoxml(myobj);