Mondeo
Centurion
MrPaul kindly helped me a while ago with the following code
This worked fine for the previous problem, now want to use it on a different project, but struggling!
Basically I have 5 instances of a custom class as follows
I want to dynamically check the value of a property within the matrixvehicle classes.
Ideally I need a method that can do this.
Is this possible?
Thanks
Visual Basic:
'Somewhere in your header section:
Imports System.Reflection
'Assume [i]myVehicle[/i] is the instance of Vehicle which you wish to alter and
'that [i]propertyName[/i] and [i]propertyValue[/i] contain the property name and value
Dim vehType As Type
vehType = myVehicle.GetType()
'Get the type of myVehicle
'Now, invoke a member to set the property
vehType.InvokeMember(propertyName, _
BindingFlags.Public Or BindingFlags.Instance Or _
BindingFlags.SetProperty Or BindingFlags.FlattenHierarchy, _
Nothing, _
myVehicle, _
New Object() {propertyValue} _
)
Basically I have 5 instances of a custom class as follows
Visual Basic:
veh2yr10non = New MatrixVehicle(matrixID, "10000", "0", "2")
veh2yr20non = New MatrixVehicle(matrixID, "20000", "0", "2")
veh2yr30non = New MatrixVehicle(matrixID, "30000", "0", "2")
veh2yr40non = New MatrixVehicle(matrixID, "40000", "0", "2")
veh2yr50non = New MatrixVehicle(matrixID, "50000", "0", "2")
Ideally I need a method that can do this.
Visual Basic:
Private Function GetClassProperty(byval classinstance as string, byval propertyinclass as string) as string
End Function
Dim s as string = GetClassProperty("veh2yr20non","chprice")
Thanks
Last edited by a moderator: