How to determine calling method and class name? [duplicate]

Try doing something like this:

var mth = new StackTrace().GetFrame(1).GetMethod();
var cls = mth.ReflectedType.Name;
// where 1 illustrates how deep into the stack to reflect.

There are more elegant solutions in C# 5.0 >, however if you are using older frameworks, the above will help.

Leave a Comment