I want to create a collection of factory methods that can instantiate various objects whose type will be known only at runtime. I can easily create a delegate for this:
delegate T InstanceCreator<T>()
but this gives a compiler error: "cannot resolve T character"
Dictionary<string, InstanceCreator<T>>
so instead i just declare
Dictionary<string, Delegate>
I tried to fill this lack of type specificity in the Add method, but ran into the same problem.
public void AddFactory(string typeName, InstanceCreator<T> factory)
Is there a better way to make sure that only InstanceCreator<T> delegates are added to the collection?
source share