I don’t know about elegant, but the way to do it is:
typeof(Creator)
.GetMethod("CreateAnimals")
.MakeGenericMethod(type)
.Invoke(creator, new object[] { 5 });
More Related Contents:
- KeyValuePair with generic values [closed]
- How do I clone a generic list in C#?
- Remove duplicates from a List in C#
- How to dynamically create generic C# object using reflection? [duplicate]
- Why isn’t there generic variance for classes in C# 4.0?
- Generics and casting – cannot cast inherited class to base class
- What is the best way to clone/deep copy a .NET generic Dictionary?
- Generic TryParse
- Generic constraints, where T : struct and where T : class
- Nullable type issue with ?: Conditional Operator
- How do I implement IEnumerable
- What does “where T : class, new()” mean?
- Generic All Controls Method
- How to solve Operator ‘!=’ cannot be applied to operands of type ‘T’ and ‘T’ [duplicate]
- explicitly cast generic type parameters to any interface
- .NET – Convert Generic Collection to DataTable
- Specifying generic collection type param at runtime [duplicate]
- Using Statement with Generics: using ISet = System.Collections.Generic.ISet
- C# Generic Type Inference With Multiple Types
- SortedList, SortedDictionary and Dictionary
- How do I check if a given value is a generic list?
- Declare a generic type instance dynamically [duplicate]
- Creating a Math library using Generics in C#
- Accessing properties through Generic type parameter
- Filtering out values from a C# Generic Dictionary
- How do generics get compiled by the JIT compiler?
- How to convert c# generic list to json using json.net?
- Build c# Generic Type definition at runtime
- Initializing a Generic variable from a C# Type Variable
- Generic Web Api controller to support any model