convert name of object into object itself

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

i have a class with a great number of private properties ...

the class contains various functions that accept as a parameter the name of
one of the private properties. the functions perform various operations on
the current value of the property ...

in the function's internal code, i'd like to obtain the value of the
relevant property without doing a lengthy

Select pParameterName
Case "MyParam1"
ParameterValue = mMyParam1
etc.

does .NET provide a mechanism to convert a string giving the name of an
object into the object itself?
 
Hi John,

Strange patterns occur sometimes. The same question but from a different
viewpoint appears only minutes apart from yours. So the same answer for both!
;-)

Have a look and see if CallByName is of any use to you.

If that's not suitable, the next to look at is the Type class. (use
GetType on the object which owns the method/member that you are interested.
This has GetField/GetFields and GetMember/s which may do the job.

Regards,
Fergus
 
How does one programmatically determine the type of an object, such as a
control ... ?

If MyControl.GetType() = HTMLControls.HTMLSelect Then

doesn't work ...

nor does

If MyControl.GetType() Is HTMLControls.HTMLSelect Then
 
John A Grandy said:
How does one programmatically determine the type of an object, such
as a control ... ?

If MyControl.GetType() = HTMLControls.HTMLSelect Then

doesn't work ...

nor does

If MyControl.GetType() Is HTMLControls.HTMLSelect Then

If TypeOf MyControl Is HTMLControls.HTMLSelect
 
Hi John,

And the other way is long-winded:
If MyControl.GetType() Is GetType (HTMLControls.HTMLSelect) Then

So you were on the right lines but they were crossed. ;-)

With Armin's version I usually use TypeOf (MyControl) as it looks more
like a function.

Regards,
Fergus
 
* "John A Grandy said:
How does one programmatically determine the type of an object, such as a
control ... ?

If MyControl.GetType() = HTMLControls.HTMLSelect Then

\\\
If TypeOf MyControl Is HTMLControls.HTMLSelect Then
...
End If
///
 
Back
Top