Set instance property by name (at runtime)

Hey guys,

how can I set a property of an instance when I have the property name saved in a variable?

// Car class is defined to have the property "interior_color" (String)

Dim vw_golf As New Car
Dim car_property As String  = "interior_color"

//how can I set the property without naming it explicitly in the code?
vw_golf.value(car_property) = "black"

Thanks guys!

  1. introspection
  2. dont use properties
    its more work but it has a ton of flexibility
    you create a class that can represent a property (it has a name, type, value etc) and then every one of your classes can have an array of these

Another alternative is Operator_Lookup. Or just use a Dictionary.

Thanks for the hints!

I got it to work with PropertyInfo.Value