Usually I do this:
MyCustomDocument1 bla1=new MyCustomDocument1()
temp.GeneratesSingleDocument<MyCustomDocument1>(bla1);
MyCustomDocument2 bla2=new MyCustomDocument2()
temp.GeneratesSingleDocument<MyCustomDocument2>(bla2);
MyCustomDocument3 bla3=new MyCustomDocument3()
temp.GeneratesSingleDocument<MyCustomDocument3>(bla3);
But this time I have a list(with all the classes from above):
List<object> allObjects = new List<object>();
It is filled like this(all objects I need):
allObjects.Add(new MyCustomDocument1());
allObjects.Add(new MyCustomDocument2());
allObjects.Add(new MyCustomDocument3());
allObjects.Add(new MyCustomDocument4());
allObjects.Add(new ...());
Now I want to call my generic method with my previous filled list ``:
foreach (var item in allObjects)
{
try
{
//instead of manually calling:
//temp.GeneratesSingleDocument<MyCustomDocument1>(bla1);
//do it generic
temp.GeneratesSingleDocument<typeof(item)>(item);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
This does not work:
temp.GeneratesSingleDocument<typeof(item)>(item);
The overall aim is to make some automation, otherwise I have to write a lot of code.
I think this is different from this post.
Thank you.
GenerateSingleDocumentlook like? Why is it even generic if you can pass any old object into it? Looks like you need to define an interface for what's common across your classes and have GenerateSingleDocument accept that interface.GeneratesSingleDocumentwill match only a few of them, inside that method there is a wswitch case checking for its type and than doing its work), actuallyGeneratesSingleDocumentits an interface method :) .But I want to generate documents for certain classes, it is just for testing.