Depending on your design, you can create a set of instances (instances of the compile-time instance) (you can store in a static class ).
For example:
static class Factory<T> { public Func<T> Creator { get; set; } } var instance = Factory<TSomething>.Creator();
This will only help if you can prefill the factory with the appropriate types.
If all you have is Type (as opposed to a generic parameter), you can store delegates in Dictionary<Type, Func<object>> , although this will be less efficient due to casting.
You still need to fill out the dictionary.
SLaks
source share