title: How do I check enum property when the property is obtained from dynamic in C#?
body: <p>Suppose I know that property <code>Color</code> of an object returns an enumeration that looks like this one:</p>
  
  <pre><code>enum ColorEnum {
     Red,
     Green,
     Blue
  };
  </code></pre>
  
  <p>and I want to check that a specific object of unknown type (that I know has <code>Color</code> property) has <code>Color</code> set to <code>Red</code>. This is what I would do if I knew the object type:</p>
  
  <pre><code>ObjectType thatObject = obtainThatObject();
  if( thatObject.Color == ColorEnum.Red ) {
     //blah
  }
  </code></pre>
  
  <p>The problem is I don't have a reference to the assembly with <code>ColorEnum</code> and don't know the object type.</p>
  
  <p>So instead I have the following setup:</p>
  
  <pre><code>dynamic thatObject = obtainThatObject();
  </code></pre>
  
  <p>and I cannot cast because I don't know the object type (and the enum type). How should I check the <code>Color</code>?</p>
  
  <pre><code>if( thatObject.Color.ToString() == "Red" ) {
      //blah
  }
  </code></pre>
  
  <p>does work but it looks like the worst examples of cargo cult code I've seen in "The Daily WTF".</p>
  
  <p>How do I do the check properly?</p>