Announcement

Collapse
No announcement yet.

Access to Properties via Variable

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access to Properties via Variable

    Hello,

    I've a tricky problem and I've searched for some time now and found nothing... Maybe somebody here is able to help me or give a hint where to look for further information.

    I'm looking for a way in order to access the property of an object not directly but via the name of the property:
    Not
    Dim Var1 as String = MyObject.myProperty
    But
    Dim Var1 as String = MyObject.Properties("myProperty")

    It doesn't have to be exactly this way, but I hope the idea became clear.

    If you have any hint on how to do that, please tell me. I'm able to change the Class MyObject, because I've written it myself. But generally there should be a way to do this with objects that I cannot change.
    I know how to get a list of Properties of an object, but I don't know how to get or set the properties value via the name of the Property (as shown above).

    Thanks in advance!

  • #2
    Hi,

    the Type.GetProperty() method gives a PropertyInfo object. Then you can use the SetValue() method.

    I hope it helps. Juergen

    Comment


    • #3
      Vielen Dank für die Antwort, Juergen! Es hat zum Durchbruch geholfen.

      Gabriel

      Comment

      Working...
      X