473,806 Members | 2,944 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Discovering calling method name and its parameters

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

public void MethodName(stri ng param1, int param2)
{
MyObject.GetInf o();
}

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.Reflecti on?

Joe
Jul 21 '05 #1
2 1792
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******@discu ssions.microsof t.com> a écrit dans le message de
news:DC******** *************** ***********@mic rosoft.com...
Here is a method that calls a static GetInfo() method on the MyObject class.
public void MethodName(stri ng param1, int param2)
{
MyObject.GetInf o();
}

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.Reflecti on?

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.Reflecti on
Imports System.Diagnost ics

Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) 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.GetPara meters()
MessageBox.Show (oParam.Name & " - " & oParam.Paramete rType.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(stri ng param1, int param2)
{
MyObject.GetInf o();
}
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.Reflecti on?

Joe


Jul 21 '05 #3

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

Similar topics

6
6905
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 conflict with one another." I've run the same stored procedure with the same exact list of arguments in Query Analyser in SQL Server, and it works. The page has the adovbs constants. Note that uspGetProperties is a stored procedure in SQL...
3
2216
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 this way: the method with 4 parameters is coded first and then the one with 2 parameters. I created very simple ASP page to call these two methods. Calling the method with 4 params has no problem. However, calling the method with 2 params I get the...
4
5575
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 someone point me in the right direction on how to call an Oracle package into a datagrid?? something like:
0
2252
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. Any help would really be appreciated. Thx
7
4990
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 Parameter. I can call the first Method without Problems, the Parameter can be deserialized by the WebService. But if I want to call the second Method and give it an Array of Parameters, then the following exception is thrown by the WebService:...
2
222
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() method to find out the name and parameters of the method it was called from?
7
3097
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 works fine. So I deploy the webservice on a remote machine (Linux box) and I get an error when calling the service. BUT: I can retrieve the WSDL and make a webreference in my VS.NET project, so obviously I (or more correct: My VS.NET project) am...
3
4293
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 web services using HTTP protocol, which is not acceptible - generating SOAP messages for arbitrary web services is something i wish to avoid. I need a package/tool that generates web service proxies that will do
2
3620
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 service locally on my development PC. If I set cookieless to true in the web.config file and then use the test form in the browser to try out the method, the method fails. I get the following message in the browser: System.InvalidOperationException:...
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10369
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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 we have to send another system
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.