(Action<T>).Name does not return expected values

Posted by Tomas Lycken on Stack Overflow See other posts from Stack Overflow or by Tomas Lycken
Published on 2010-04-05T23:45:05Z Indexed on 2010/04/05 23:53 UTC
Read the original article Hit count: 120

Filed under:
|
|

I have the following method (used to generate friendly error messages in unit tests):

protected string MethodName<TTestedType>(Action<TTestedType> call)
{
    return string.Format("{0}.{1}", typeof(TTestedType).FullName, call.Method.Name);
}

But when I call it as follows, I don't get the expected results:

var nm = MethodName<MyController>(ctrl => ctrl.Create());

After running this code, nm contains "<Create_CreateShowsView>b__8", and not (as expected) "Create". How should I change the code to obtain the expected result?

© Stack Overflow or respective owner

Related posts about c#

Related posts about delegates