I'm trying to write a function that can reliably know the name of the
calling method. I've figured out how to do this:
string methodname = (new StackTrace()).GetFrame(1).GetMethod().Name;
This seems to get the name of the method that called the current
method. But there are two problems. One is that I have to hardcode
one step back in the stack. When switching to a release build, this
may not work corerctly because of optimization. The other, more
serious problem is that the method name is stripped from release
buildes.
Is there a way, like with an attribute for example, to force the
compiler not to inline certain functions?
Also, clearly reflection has to work in release builds. So it's
possible in a release build to know the name of a method in a class.
It's also possible to get the stack frame, but without the name
property filled in. Is there a way to correlate the two? Some kind of
handle that is set in the release build stack frame that can be
compared to something in reflection so I can get the name, like a
bridge between the stack frame and reflection?
One of the requirements of what I'm doing is that they want tracing and
performance monitoring to be as unobtrusive as possible while still
working with release builds in production.
tia, brian