So I have some code that sets a property on an object.
Expression<Func<string>> propertyToValidate; //passed in above
var underlyingProperty = ((PropertyInfo)((MemberExpression)propertyToValidate.Body).Member);
underlyingProperty.SetValue(objectUnderTest, excessivelyLargeNameValue);
And this works well, when propertyToValidate
is something like "Car.Name
or Fish.Color
". Now I have situations where I want to pass nested paths, something like Car.Door.Handle.Name
or Fish.Fin.Style
or something of that sort. When I try to do that, I receive an error:
Object does not match target type.
I suspect it is trying to call the Name
property on the Car
, instead of the Handle
. How can I modify my code to handle this 'nested' case?
Aucun commentaire:
Enregistrer un commentaire