Using nameof to get name of current method

You can’t use nameof to achieve that, but how about this workaround:

The below uses no direct reflection (just like nameof) and no explicit method name.

Results.Add(GetCaller(), result);

public static string GetCaller([CallerMemberName] string caller = null)
{
    return caller;
}

GetCaller returns the name of any method that calls it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)