Calling a generic method with a dynamic type [duplicate]

I don’t know about elegant, but the way to do it is:

typeof(Creator)
    .GetMethod("CreateAnimals")
    .MakeGenericMethod(type)
    .Invoke(creator, new object[] { 5 });

Leave a Comment