How to vary the type of a List<T> method parameter at runtime?
How to vary the type of a List<T> method parameter at runtime?
(OP)
I have a generic method, so:
There are two possibilities for <T>: <Category> and <ProductSupplier>. Previous to this call, I have a method which uses reflection to get a List<T> object (at least, I think it is; Invoke returns an object object and setting myList to dynamic allows me to access the data properties), populated with either Category or ProductSupplier data:
where cRet is an object with GetCategories() and GetProductSuppliers() methods, and parms.data is a string with either "GetCategories" or "GetProductSuppliers" as a value.
So, what I would like to be able to do is inject either of the two possibilities for <T> into the Export method at runtime. The parm object is a set of parameters that are passed into a worker method pursuant to a ParameterizedThreadStart call.
Is this doable?
CODE
public void Export<T>(List<T> exportList, string filePath, byte fileType) where T: class
There are two possibilities for <T>: <Category> and <ProductSupplier>. Previous to this call, I have a method which uses reflection to get a List<T> object (at least, I think it is; Invoke returns an object object and setting myList to dynamic allows me to access the data properties), populated with either Category or ProductSupplier data:
CODE
dynamic myList = cRet.GetType().GetMethod(parms.data).Invoke(cRet, null)
where cRet is an object with GetCategories() and GetProductSuppliers() methods, and parms.data is a string with either "GetCategories" or "GetProductSuppliers" as a value.
So, what I would like to be able to do is inject either of the two possibilities for <T> into the Export method at runtime. The parm object is a set of parameters that are passed into a worker method pursuant to a ParameterizedThreadStart call.
Is this doable?
An unforeseen consequence of the information revolution has been the exponential propagation of human error.
RE: How to vary the type of a List<T> method parameter at runtime?
CODE
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:
CODE
so the problem is moot. I've already been able to derive the right List ("someCategoryList" in my example) using Reflection, so problem solved.
An unforeseen consequence of the information revolution has been the exponential propagation of human error.