I have an object with primitive and complex properties.
I have to get property values by reflection.
I use this statements:
Dim propertyInfo As PropertyInfo = MYITEM.GetType().GetProperty("MyProp1")
Dim propertyValue As Object = propertyInfo.GetValue(MYITEM, Nothing)
and it'ok, but if I use the same code with complex property like this...
Dim propertyInfo As PropertyInfo = MYITEM.GetType().GetProperty("MyProp1.MyProp2")
Dim propertyValue As Object = propertyInfo.GetValue(MYITEM, Nothing)
the propertyInfo is null and I can't read the value of "MyProp2".
Exist an generic method to do this?
MyProp1.MyProp2 is not a property of your base object, MyProp1 is a property of that then MyProp2 is a property of the object returned by MyProp1.
Try this :
You could try something like this extension method (sorry its in c#)
Then to test
Usage