473,385 Members | 1,655 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.

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 1758
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: 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: 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...
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...
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...

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.