473,394 Members | 1,840 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,394 software developers and data experts.

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 1895
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...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.