question

StevenYoung-5410 avatar image
0 Votes"
StevenYoung-5410 asked PengGe-MSFT edited

How to invoke the property base on the string?

dim x as string="abc"

//I want to get or set the property using the string x, how to do?

Public Property abc() As Boolean
Get
Return true
End Get
Set(ByVal Value As Boolean)
If value=true Then
.....
End If
End Set
End Property

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

Try something like this:

 Dim p = obj.GetType.GetProperty(x)
    
 ' Getting value: '
 Dim value As Boolean = CBool(p.GetValue(obj))
    
 ' Setting value: '
 p.SetValue(obj, some_new_value)

where obj is the object that contains this property.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.