473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Walking the function stack --- Reflection question.

I know you can use the property
System.Reflection.MethodInfo.GetCurrentMethod().Na me to get the name
of the function currently be executed.

What I want to do is get the name of the function which called the
function I am currently in.

For example (pardon my pseudo-code):

public void ABC()
{
// Do some stuff here

XYZ();
}

public void XYZ()
{
//I want to determined the name of the function that called XYZ.
//In this case, ABC

}

Any thoughts???

Thanks -

Tim Burda
Ti*******@si-intl.com
Nov 15 '05 #1
4 1897
This could be possible usint the StackTrace class in the System.Diagnostics
namespace. There is a nice article about this topic on the CodeProject:
http://www.codeproject.com/csharp/cu...asp?print=true
--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Tim Burda" <Ti*******@si-intl.com> schreef in bericht
news:bc**************************@posting.google.c om...
I know you can use the property
System.Reflection.MethodInfo.GetCurrentMethod().Na me to get the name
of the function currently be executed.

What I want to do is get the name of the function which called the
function I am currently in.

For example (pardon my pseudo-code):

public void ABC()
{
// Do some stuff here

XYZ();
}

public void XYZ()
{
//I want to determined the name of the function that called XYZ.
//In this case, ABC

}

Any thoughts???

Thanks -

Tim Burda
Ti*******@si-intl.com

Nov 15 '05 #2
StackTrace st = new StackTrace ()
if ( st.FrameCount > 0 )

StackFrame sf = st.GetFrame (i)
Debug.WriteLine ( sf.GetMethod ())
HT

Rafat Sarosh
Nov 15 '05 #3
Rafat Sarosh <an*******@discussions.microsoft.com> wrote in message news:<8E**********************************@microso ft.com>...
StackTrace st = new StackTrace ();
if ( st.FrameCount > 0 )
{
StackFrame sf = st.GetFrame (i);
Debug.WriteLine ( sf.GetMethod ());
}

HTH

Rafat Sarosh


Thanks to all who responded, I have solved the initial problem, but
now let's say I passed a parameter to the function. I can easily the
get name and type of the parameter, but in the ParameterInfo object, I
don't see a way to get the value.

Is this possible?
Nov 15 '05 #4
Tim Burda <Ti*******@si-intl.com> wrote:
Thanks to all who responded, I have solved the initial problem, but
now let's say I passed a parameter to the function. I can easily the
get name and type of the parameter, but in the ParameterInfo object, I
don't see a way to get the value.

Is this possible?


No, it's not.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5

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

Similar topics

0
by: Jay Allard | last post by:
Hello I posted this in the vb.net group on the 2/25/2004, but didn't get any response. Here's attempt 2. Does anyone know of a more appropriate place to post this? One new piece of...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
1
by: Jason Coyne | last post by:
I am trying to use the StackTrace class to get my current stack trace for some logging. Everything is working fine, except when I am using threading (specifically WaitCallBack and...
1
by: Zachary Hartnett | last post by:
I was trying to write a routine this morning that would open a given assembly, walk the inheritance tree of classes in the assembly, and provide a list of classes in the assembly that inherit from...
9
by: Kishor | last post by:
Hi all, I am Using VB.Net for developing my application. I am now needed help. In this project I have to execute some function, but I cannot call them directly using function name, I wanted to...
1
by: Marco | last post by:
Hi all I am using .NET reflection to examine a stack trace, using the StackTrace, StackFrame, MethodInfo, ParameterInfo and FieldInfo classes. I can easily discover all methods in the call...
2
by: Don | last post by:
This may seem like an odd question, but is it possible to get the name of the class & function that is calling a function of another class? e.g. Public Class CallerName Public Shared Function...
7
by: Brad Pears | last post by:
I am developing a simple error message class and would like the be able to generate as part of the message the curent class/module/form and function or sub that the error was generated in without...
11
by: Simon Woods | last post by:
Hi I have this recursive function and I want to walk the inheritance hierarchy to set field values .... the generic T is constrainted as the base class of the inheritance hierarchy Friend...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.