June 2003
Intermediate to advanced
800 pages
34h 20m
English
You want your class to determine some information about the calling code, probably for diagnostic purposes.
Use the System.Diagnostics.StackTrace class.
You can’t retrieve information about the caller of a procedure through reflection. Reflection can only act on metadata stored in the assembly, whereas the caller of a procedure is determined at runtime. However, .NET includes two useful diagnostic classes that fill this role: StackTrace and StackFrame.
The stack holds a record of every call that is open and not yet completed. As new calls are made, new methods are added to the top of the stack. For example, if method A calls method B, both method A and B will be on the stack (with method ...
Read now
Unlock full access