Is it possible to get the name of a local variable from a reference to the variable? For example, I can get the names and values of a calling function's parameters like this:
- Code: Select all
Dim frame As New StackFrame(1)
Dim pInfos() As ParameterInfo = frame.GetMethod().GetParameters()
Is there some way to get the same information for a calling function's local variables? This is kind of what I have in mind:
- Code: Select all
Sub SomeSub()
Dim count As Integer = 10
Dim average As Single = 45.67
LogLocalVariables(count, average)
End Sub
Sub LogLocalVariables(ByVal var1 As Object, ByVal var2 As Object)
' I can get each variable's type like this:
Dim mBody As MethodBody = GetType(Form1).GetMethod _
("SomeSub").GetMethodBody()
Dim varList As ObjectModel.ReadOnlyCollection(Of LocalVariableInfo) = _
mBody.LocalVariables
' But what I really want is info like this:
' count = 10
' average = 45.67
End Sub
Thanks.
--Clay


