M
Merk
How can I programmatically determine the [name of a method] from within that
method.
For example, consider the following code:
private void DoSomething()
{
string s = ???;
}
How can I get the string, "DoSomething" into the variable s? (without
hard-coding the method name)?
The reason I want to do this is that I have a centralized error logging
routine in a static class and I call it from error handlers throughout the
application. One of the parameters in the error logging routine is the name
of the method [from which the error logging routine is being called]. I
would like to cut-n-paste the line that calls the static error logging
routine, and I don't want to hard-code the method name into that line of
code. Maybe there is an easier way to go about this than what I'm now
looking to do. I'd prefer to not parse the stack trace (from within the
error logging routine) if there is an easier way.
Thanks!
method.
For example, consider the following code:
private void DoSomething()
{
string s = ???;
}
How can I get the string, "DoSomething" into the variable s? (without
hard-coding the method name)?
The reason I want to do this is that I have a centralized error logging
routine in a static class and I call it from error handlers throughout the
application. One of the parameters in the error logging routine is the name
of the method [from which the error logging routine is being called]. I
would like to cut-n-paste the line that calls the static error logging
routine, and I don't want to hard-code the method name into that line of
code. Maybe there is an easier way to go about this than what I'm now
looking to do. I'd prefer to not parse the stack trace (from within the
error logging routine) if there is an easier way.
Thanks!