Which Method Am I In?-Collection of common programming errors
If you’re using .NET 4.5 you can use the CallerMemberName attribute:
public static GetCallerMemberName([CallerMemberName]string caller = null)
{
return caller;
}
Note that when calling this method you don’t need to pass anything as an argument – the C# compiler does the work for you. This also means that you avoid performing reflection at runtime, which makes this method much faster.
Usage:
void DoSomething()
{
#if Debug
Log("Now In " + GetCallerMemberName());
#endif
}