Getting refference to a method parameters

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

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
 
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
 
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.
 
Back
Top