473,473 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Determine caller class name

Hi!

Is there a way in VB.NET to determine the caller's class name?

System.Reflection.MethodBase.GetCurrentMethod.GetT ype basically telling
me what is my current executing class, but I wanted to know, which
caller class invoke my existing class method.

Any help is much appreciated.
Bob

May 31 '06 #1
2 7282
qi*****@gmail.com wrote:
Is there a way in VB.NET to determine the caller's class name?


\\\
Dim stack As New StackTrace
Dim className As String

className = stack.GetFrame(1).GetMethod.DeclaringType.Name
///

The StackTrace object will contain details about the current call stack. The
first element in the collection (element zero) will be your own current
method, elements with higher indices will be the methods further up the
call-stack. As the code that calls you will always be the second element on
the call stack, you can access it using stack.GetFrame(1).

HTH,

--

(O)enone
May 31 '06 #2
Thanks a lot. It definitely helps.

Oenone wrote:
qi*****@gmail.com wrote:
Is there a way in VB.NET to determine the caller's class name?


\\\
Dim stack As New StackTrace
Dim className As String

className = stack.GetFrame(1).GetMethod.DeclaringType.Name
///

The StackTrace object will contain details about the current call stack. The
first element in the collection (element zero) will be your own current
method, elements with higher indices will be the methods further up the
call-stack. As the code that calls you will always be the second element on
the call stack, you can access it using stack.GetFrame(1).

HTH,

--

(O)enone


Jun 6 '06 #3

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

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
9
by: jaden10001 | last post by:
I have read that the function.caller method is now depricated. I see alot of browsers still support it but Opera 7 does not. Is there a way to get the name of the caller of a function in Opera 7?
21
by: Joakim Hove | last post by:
Hello, I have implemented a small library with a function a datatype to manage temporary storage, and handle out correctly casted storage. The function to get a double pointer is for instance: ...
2
by: Fabio Cannizzo | last post by:
Is it possible to know who is the caller of some running method? In ogther words, given a method of some class which is running, is there a way, inside the method, to find out from which namespace...
4
by: Hmnt | last post by:
Hi Hope ur smart enough to get what i wanna ask ... (from the sub line Brief Explaination I've 2 classas Class1 and Class Now i've an instance of Class2 ( Class2 objC2 = new Class2(); Next i...
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
1
by: qingxun | last post by:
Hi! Is there a way in VB.NET to determine the caller's class name? System.Reflection.MethodBase.GetCurrentMethod.GetType basically telling me what is my current executing class, but I wanted...
8
by: Ole | last post by:
If I define a class and create a instant of it like e.g.: UserClass instantName = new UserClass(); how do I then determine the defined name "instantName" in the UserClass e.g. in a method (or...
3
by: Francesco Guerrieri | last post by:
Hi, Today I've been thinking a bit about the "python internals". Inspired by this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062 I found out a little problem which...
3
by: Peter | last post by:
Hi I call some "worker"-Methods asyncronous. here some simplified code .... public delegate long AsyncWCaller(string parameter); ....
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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
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...
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,...
1
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.