|
-
Mar 17th, 2004, 07:08 AM
#1
Thread Starter
Hyperactive Member
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?
-
Mar 17th, 2004, 08:51 AM
#2
Fanatic Member
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 .
-
Mar 17th, 2004, 12:56 PM
#3
Thread Starter
Hyperactive Member
This code will display the Assembly, Process and Parameters (names and Types - sadly not the values) that are in the stack...
VB Code:
Try
'*********************************************
'* Define Stack Related Objects
'*********************************************
Dim objDisplay As New System.Text.StringBuilder
Dim objParameters() As System.Reflection.ParameterInfo
Dim strParams As String
Dim intParams As Int32
Dim objStackTrace As New System.Diagnostics.StackTrace
Dim objStackFrame As System.Diagnostics.StackFrame
Dim objStackFrameMethod As System.Reflection.MethodBase
Dim intFrameCount As Int32 = 0
'**********************************************
'* Return Stack Details
'**********************************************
For intFrameCount = 0 To objStackTrace.FrameCount - 1
objStackFrame = New System.Diagnostics.StackFrame
objStackFrame = objStackTrace.GetFrame(intFrameCount)
objStackFrameMethod = objStackFrame.GetMethod()
objDisplay.Append(objStackFrameMethod.ReflectedType.FullName & vbCrLf)
objDisplay.Append(" " & objStackFrameMethod.Name & vbCrLf)
objParameters = objStackFrameMethod.GetParameters
For intParams = 0 To objParameters.Length - 1
objDisplay.Append(" Name=")
objDisplay.Append(objParameters(intParams).Name)
objDisplay.Append(", Type=")
objDisplay.Append(objParameters(intParams).ParameterType.Name)
objDisplay.Append(vbcrLf)
Next
Next
return objDisplay.ToString
-
Mar 17th, 2004, 01:51 PM
#4
Fanatic Member
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.
-
Mar 17th, 2004, 01:54 PM
#5
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|