C# - Class Type as Parameter in methods
- by Claudio
Hi guys,
I'm using SQLite.cs wrapper for helping me with the database and I have this method for create XML from a table, that is working fine.
public void GenerateInvoiceXML(string filePath) {
var invoices = app.db.Table<Invoice>().ToList();
XmlSerializer serializer = new XmlSerializer( typeof(List<Invoice>) );
TextWriter writer = new StreamWriter(filePath);
serializer.Serialize(writer,invoices);
writer.Close();
}
All tables that I have are defined like this:
[Serializable]
public class Invoice
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Supplier {get; set;}
public string Date {get; set;}
public string PaymentMethod {get; set;}
public string Notes {get; set;}
public Invoice(int newID)
{
Id = newID;
}
public Invoice()
{
}
}
But I want to change this method for something like this:
public void GenerateInvoiceXML(string filePath, Type table) {
var dataForXML = app.db.Table<table>().ToList();
XmlSerializer serializer = new XmlSerializer( typeof(List<table>) );
TextWriter writer = new StreamWriter(filePath);
serializer.Serialize(writer,dataForXML);
writer.Close();
}
Does anybody have an idea how to do it?
Kind Regards,
Claudio