Suppose I know that the Color property of an object returns an enumeration that looks like this:
enum ColorEnum { Red, Green, Blue };
and I want to check that for a certain object of an unknown type (which, as I know, has the Color property), Color set to Red . This is what I would do if I knew the type of object:
ObjectType thatObject = obtainThatObject(); if( thatObject.Color == ColorEnum.Red ) {
The problem is that I do not have a reference to the assembly with ColorEnum and do not know the type of object.
So instead, I have the following setting:
dynamic thatObject = obtainThatObject();
and I canโt use because I donโt know the type of the object (and the type of enumeration). How to check Color ?
if( thatObject.Color.ToString() == "Red" ) {
really works, but it looks like the worst example of a load cookie I saw in "The Daily WTF".
How to perform a validation?
source share