473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Getting name of caller

Dan
I'm implementing a tracing class with a WriteLine method, and would like to
record the name of the function which is calling WriteLine. Is there a way
to do this?
Nov 16 '05 #1
2 1061
Dan,

In this case, you would want to create an instance of the StackFrame
class, passing 1 to the constructor indicating that you want to get the
stack frame for the one above the currently executing code.

Once there, you can get the MethodInfo instance for that method, and get
the name of the method, as well as the type.

However, this can have a hit on performance (walking the stack usually
does).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:ua**************@TK2MSFTNGP09.phx.gbl...
I'm implementing a tracing class with a WriteLine method, and would like
to
record the name of the function which is calling WriteLine. Is there a
way
to do this?

Nov 16 '05 #2
Dan
Thanks Nicholas.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:er**************@TK2MSFTNGP09.phx.gbl...
Dan,

In this case, you would want to create an instance of the StackFrame
class, passing 1 to the constructor indicating that you want to get the
stack frame for the one above the currently executing code.

Once there, you can get the MethodInfo instance for that method, and get the name of the method, as well as the type.

However, this can have a hit on performance (walking the stack usually
does).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:ua**************@TK2MSFTNGP09.phx.gbl...
I'm implementing a tracing class with a WriteLine method, and would like
to
record the name of the function which is calling WriteLine. Is there a
way
to do this?


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: ivan_oj28 | last post by:
Hi, I am developing an application where I need to read the caller id from an incoming call. The only info (for now) I need is the caller id info, so that I can display the propper caller info on...
17
by: warteschlange | last post by:
is there a way to find out the object/function name from inside object/function. function coffee(){ alert(this.someHowGetMyNameFuncOrVar); => should give me 'coffee' } var milk = new...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
1
by: Gary Robinson | last post by:
Alex Martelli has a cookbook recipe, whoami, for retrieving the name of the current function: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062. It uses sys._getframe(). I'm a little wary...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.