I have a class that takes a Generic Type as part of its initialization.
public class AnimalContext<T>
{
public DoAnimalStuff()
{
//AnimalType Specific Code
}
}
What I can do right now is
AnimalContext<Donkey> donkeyContext = new AnimalContext<Donkey>();
AnimalContext<Orca> orcaContext = new AnimalContext<Orca>();
But what I need/want to do is be able to declare an AnimalContext initialized to a type that is only known at runtime. For instance,
Animal a = MyFavoriteAnimal(); //returns an instance of a class
//implementing an animal
AnimalContext<a.GetType()> a_Context = new AnimalContext<a.GetType()>();
a_Context.DoAnimalStuff();
Is this even possible? I can't seem to find an answer for this online.