473,396 Members | 2,002 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,396 software developers and data experts.

Discovering calling method name and its parameters

Here is a method that calls a static GetInfo() method on the MyObject class.

public void MethodName(string param1, int param2)
{
MyObject.GetInfo();
}

Is there any way for the GetInfo() method to find out the name and
parameters of the method it was called from?

For example

public static void GetInfo()
{
// Is there some query I can make that would return the name 'MethodName'
// and the names of its parameters 'param1' and 'param2' and their values?
}

Can this be done with System.Reflection?

Joe
Jul 21 '05 #1
2 1760
See the StackFrame class. You can have the name of the method. Likely its
parameters (you have this info anyway in reflection). Not sure though about
the values.

Please let us know about your findings...

Patrice

--

"juchytil" <ju******@discussions.microsoft.com> a écrit dans le message de
news:DC**********************************@microsof t.com...
Here is a method that calls a static GetInfo() method on the MyObject class.
public void MethodName(string param1, int param2)
{
MyObject.GetInfo();
}

Is there any way for the GetInfo() method to find out the name and
parameters of the method it was called from?

For example

public static void GetInfo()
{
// Is there some query I can make that would return the name 'MethodName' // and the names of its parameters 'param1' and 'param2' and their values? }

Can this be done with System.Reflection?

Joe

Jul 21 '05 #2
Joe,

As Patrice mentioned, you can get the method information using the Stackframe
class. Here's how you would do it:

Imports System.Reflection
Imports System.Diagnostics

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
TestStackFrame()
End Sub

Private Sub TestStackFrame()
' 0 means start from current stack frame
Dim oTrace As New StackTrace(0, True)
' 0 means the current stack frame, 1 means previous, etc
Dim oMethod As MethodBase = oTrace.GetFrame(1).GetMethod
MessageBox.Show(oMethod.Name)
For Each oParam As ParameterInfo In oMethod.GetParameters()
MessageBox.Show(oParam.Name & " - " & oParam.ParameterType.Name)
Next
End Sub

The above code will print out Button1_Click and its parameters.

However!
I'm not sure there's an easy way to get the parameter values. You surely
cannot get the values using either reflection or the Stack classes. You might
be able to use debugger APIs to get the values but that might be a little
more complicated. I haven't seen anyone do this before so I would surely
love to know if you find a way to get the method parameter values.
hope that helps..
Imran.
Here is a method that calls a static GetInfo() method on the MyObject
class.

public void MethodName(string param1, int param2)
{
MyObject.GetInfo();
}
Is there any way for the GetInfo() method to find out the name and
parameters of the method it was called from?

For example

public static void GetInfo()
{
// Is there some query I can make that would return the name
'MethodName'
// and the names of its parameters 'param1' and 'param2' and their
values?
}
Can this be done with System.Reflection?

Joe


Jul 21 '05 #3

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

Similar topics

6
by: dw | last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a connection. Every time I do, it generates an error "Arguments are of the wrong type, are out of acceptable range, or are in...
3
by: Cindy Liu | last post by:
Hi Everyone, I created C# COM+ component. It has two overloaded methods - the method names are same and their signatures are different, one takes two parameters and another takes four. I coded...
4
by: Jeff | last post by:
Help!! I'm trying to convert a visual basic stand alone program into a Web Program using C#. There are a lot of Oracle packages already written that I am trying to use (unsuccessfully). Can...
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
7
by: Christian Wilhelm | last post by:
Hi! I'm trying to call a Java WebService out of a .net Client. There are two Methods, one Method requires one Parameter of type Parameter, the other Method requires one Parameter of type...
2
by: juchytil | last post by:
Here is a method that calls a static GetInfo() method on the MyObject class. public void MethodName(string param1, int param2) { MyObject.GetInfo(); } Is there any way for the GetInfo()...
7
by: Jorgen Haukland, Norway | last post by:
Hi, I have created a Java webservice which runs in IBM WebSphere appserver. I take the WSDL-file and create a VS.NET WinForm application and calls the service running on my PC and everything...
3
by: Ivan Zuzak | last post by:
Hello, My Python application calls web services available on the Internet. The web service being called is defined through application user input. The Python built-in library allows access to...
2
by: Polaris431 | last post by:
I have an ASP.NET website that includes a web service in my project as well. The web service is a class within my website and not a separate project. I am trying to call a method in my web...
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
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...
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...
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,...

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.