There are two ways that a type can be set to a method: as a Type parameter or as a parameter of a general type. In the first case, if the general class Foo<T> inherited from the base class (for example, FooBase ), which is not common for type T, you can use Dictionary<Type,FooBase> . The FooBase class can include all members (possibly abstract or virtual ) of Foo<T> whose signature does not depend on T , so code that is given a Type object for an arbitrary type but does not have a parameter of a general type will be able to do FooBase all that could be done without having a parameter of a general type. Please note: if you have a Type object and want to use it as if it were a general type, you usually need to use Reflection and build either a delegate or an instance of a class of a common class with a filled type parameter; once this has been done, you can use the second approach below.
If you have a common type of parameters (for example, one writes the method T GetThing<T>(whatever) , you can define a static general class ThingHolder<T> with a static field T theThing . In this case, for any type TT , ThingHolder<TT>.theThing will be a TT type field. With this field you can do everything you can do with TT .
source share