Reflection GetObjectByStringReference(string) as object

  • Thread starter Thread starter Andre
  • Start date Start date
A

Andre

Hi I am searching for a method like this
GetObjectByStringReference(ObjectName as string) as object

E.g.

Dim var1 as string = "Test"

Dim O as object = GetObjectByStringReference("var1")
Console.writeline("Value of O:" & O.ToString())

Should Output Test

I need this to get detailed error logging information from my methods.

I can get the Argument names my this code
Dim _methodif As Reflection.MethodInfo =
Reflection.MethodInfo.GetCurrentMethod
Dim _param() As Reflection.ParameterInfo = _methodif.GetParameters()

For Each _pi As ParameterInfo In _param
MessageBox.Show(_pi.Name)
Next

What I need is to get the object reference of a variable by the name
of the variable.

I would figure that the databinding in asp.net does this?

Please help..
 
Andre said:
Hi I am searching for a method like this
GetObjectByStringReference(ObjectName as string) as object

E.g.

Dim var1 as string = "Test"

Dim O as object = GetObjectByStringReference("var1")
Console.writeline("Value of O:" & O.ToString())

Should Output Test

I need this to get detailed error logging information from my methods.

I can get the Argument names my this code
Dim _methodif As Reflection.MethodInfo =
Reflection.MethodInfo.GetCurrentMethod
Dim _param() As Reflection.ParameterInfo = _methodif.GetParameters()

For Each _pi As ParameterInfo In _param
MessageBox.Show(_pi.Name)
Next

What I need is to get the object reference of a variable by the name
of the variable.

I would figure that the databinding in asp.net does this?

Not if var1 is a local variable. By the time it gets as far as
execution, the JIT may not even know that it ever had a name.

For instance variables, you can use reflection, but you can't get the
value of a local variable with reflection.
 
Back
Top