Delegates contain the MethodInfo
that you want in your Method
property . Thus, your helper method may be as simple as:
MethodInfo GetMethodInfo(Delegate d) { return d.Method; }
You cannot convert directly from a group of methods to Delegate
. But you can use a throw for this. For instance:.
GetMethodInfo((Action)Console.WriteLine)
Remember that this will not work if you try to mix it with something like a usr solution. for instance
GetMethodInfo((Action)(() => Console.WriteLine()))
will return MethodInfo
for the created anonymous method, and not for Console.WriteLine()
.
svick source share