I am trying to work with the class found in this post but it needs a MethodBase to run.
I read What is the fastest way to get a MethodBase object? but i couldn't get any solution to work.
What i need to do is to get the MethodBase object from a function.
For example getting the MethodBase for the static function WriteLine() of the class Console or getting the MethodBase for the non-static function Add() of a List<>.
Thanks for your help!
Method 1
You can use reflection directly:
In the case of Console.Writeline(), there are many overloads for that method. You will need to use the additional parameters of GetMethod to retrieve the correct one.
If the method is generic and you do not know the type argument statically, you need to retrieve the MethodInfo for the open method and then parametrize it:
Method 2
Some third-party libraries can help you with this. Using SixPack.Reflection, you can do the following: