I would like to get the name of the method that is being delegated as a Func.
Func<MyObject, object> func = x => x.DoSomeMethod();
string name = ExtractMethodName(func); // should equal "DoSomeMethod"
How can I achieve this?
-- For bragging rights --
Make ExtractMethodName
also work with a property invocation, having it return the property name in that instance.
eg.
Func<MyObject, object> func = x => x.Property;
string name = ExtractMethodName(func); // should equal "Property"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…