In C# I want to create a generic method that:
- Accepts a MethodInfo object as a parameter.
- Returns the object that is returned when the MethodInfo is invoked.
The source of my confusion is that I want the method to be generically typed to the same return type as the MethodInfo object that gets passed in.
You cannot do this. By definition, generics are a compile-time construct, while the return type of a particular
MethodInfois something that is only known at runtime (when you receive a specificMethodInfoinstance), and will change from call to call.