Results 1 to 5 of 5

Thread: Reflected Parameter Values

  1. #1

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    Reflected Parameter Values

    I am writing an errohandler at the moment, and I'd like to be able to record the values of any parameters passed into the sub/function where the exception occured.

    I can find the sub/function using reflection, and I can even find the names of the parameters, I would now like to take it one step further and return the values...

    Any ideas?

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    I have been using reflection to get the name of the assembly and version, but how did you get the name of the method and the parameters? Sorry I can't answer your question, and instead pose one .

  3. #3

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    This code will display the Assembly, Process and Parameters (names and Types - sadly not the values) that are in the stack...

    VB Code:
    1. Try
    2.  
    3.          '*********************************************
    4.          '* Define Stack Related Objects
    5.          '*********************************************
    6.          Dim objDisplay As New System.Text.StringBuilder
    7.          Dim objParameters() As System.Reflection.ParameterInfo
    8.          Dim strParams As String
    9.          Dim intParams As Int32
    10.          Dim objStackTrace As New System.Diagnostics.StackTrace
    11.          Dim objStackFrame As System.Diagnostics.StackFrame
    12.          Dim objStackFrameMethod As System.Reflection.MethodBase
    13.          Dim intFrameCount As Int32 = 0
    14.  
    15.          '**********************************************
    16.          '* Return Stack Details
    17.          '**********************************************
    18.          For intFrameCount = 0 To objStackTrace.FrameCount - 1
    19.             objStackFrame = New System.Diagnostics.StackFrame
    20.             objStackFrame = objStackTrace.GetFrame(intFrameCount)
    21.             objStackFrameMethod = objStackFrame.GetMethod()
    22.            
    23.             objDisplay.Append(objStackFrameMethod.ReflectedType.FullName & vbCrLf)
    24.             objDisplay.Append("    " & objStackFrameMethod.Name & vbCrLf)
    25.  
    26.             objParameters = objStackFrameMethod.GetParameters
    27.             For intParams = 0 To objParameters.Length - 1
    28.                  objDisplay.Append("      Name=")
    29.                  objDisplay.Append(objParameters(intParams).Name)
    30.                  objDisplay.Append(", Type=")
    31.                  objDisplay.Append(objParameters(intParams).ParameterType.Name)
    32.                  objDisplay.Append(vbcrLf)
    33.             Next
    34.          Next
    35.  
    36.          return objDisplay.ToString

  4. #4
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Thanks for the code!

    Also, I don't think it is possible to do what you want to do. I think Reflection examines the Class, not the Object, so I don't think there is a way to get run-time values. Also, what if you went to get the value but it was garbage collected already? I don't think you can do it, but could be wrong.

  5. #5
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Although, doing some searching, there were some references to the debugger API. Check out:

    http://msdn.microsoft.com/library/de...dn_debugeh.asp

    Might be some info for you in there.

    Hope that helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width