I have a generic method, so:
public void Export<T>(List<T> exportList, string filePath, byte fileType) where T: class
There are two possibilities for <T>
: <Category>
and <ProductSupplier>
. I don't know which one I am using in a given runtime instance; which one to use is passed as a parameter to the method calling this method.
Is it possible to pass a variable value to <T>
during runtime? I've played around with GetMethod/Invoke, etc. (I've already gotten that to work with a non-generic method), but they seem to address the method itself, rather than working as a mechanism to vary the generic List type.
[Edit]As it turns out, my question has its basis in a misunderstanding. When I first got my Export method to work at all, it was with this format:
public void Export<Category>(someCategoryList, "C:\Temp2\myFile.txt", 0)
I wanted to know how I could plug different values in for <Category>
without explicitly doing so at design time with some sort of ever-expanding switch statement. As it turns out, this works fine:
public void Export(someCategoryList, "C:\Temp2\myFile.txt", 0)
so the problem is moot. I've already been able to derive the right List ("someCategoryList" in my example) using Reflection, so problem solved.