By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

Getting refference to a method parameters

P: n/a
I am implementing a logging facility for my app, and I am looking for a
way to iterate through the parametersm passed to a method.
Something like:

Sub Test(byval ABCD as string, byval EFGH as integer)
Try
' Some Code
Catch ex as Exception
'Code to find what types are the two parameters
' and do some stuff with them like logging or something
End Try
End Sub

Of course I know that this method has two patamaters and what is their
type, but I want to write independent code, which will work for every
method. My best guess is for using reflection, but I don't know how to
reference the method's parameters.

Any ideas?

tnx

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You can try this code:

Private Sub TestMe(MyString As String, MyInteger As Integer)
Dim sf As New StackFrame(True)
Dim mb As MethodBase = sf.GetMethod()

Dim pi As ParameterInfo() = mb.GetParameters()

For Each p As ParameterInfo In pi
Console.WriteLine(p.Name & ": " & p.ParameterType.ToString)
Next
End Sub

Nov 21 '05 #2

P: n/a
What about the values?

Nov 21 '05 #3

P: n/a
Your original post did not mention getting the values.

I didn't look very deeply at the ParameterInfo class and assumed that
it would provide a method for getting the values but, alas, it does
not!

I'm not sure how you would get the values in this context.

Nov 21 '05 #4

P: n/a
Thanks Chris

Chris Dunaway wrote:
Your original post did not mention getting the values.

I didn't look very deeply at the ParameterInfo class and assumed that
it would provide a method for getting the values but, alas, it does
not!

I'm not sure how you would get the values in this context.


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.