title: Generic extension method to see if an enum contains a flag
body: <p>Considering this:</p>
  
  <pre><code>[Flags]
  public enum MyEnum {
      One = 1,
      Two = 2,
      Four = 4,
      Eight = 8
  }
  
  public static class FlagsHelper
  {
      public static bool Contains(this MyEnum keys, MyEnum flag)
      {
          return (keys &amp; flag) != 0;
      }
  }
  </code></pre>
  
  <p>Is it possible to write a generic version of Contains that would work for any <code>enum</code> and not just <code>MyEnum</code>?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This would be my version after reading your answers:</p>
  
  <pre><code>    public static bool Contains(this Enum keys, Enum flag)
      {
          ulong keysVal = Convert.ToUInt64(keys);
          ulong flagVal = Convert.ToUInt64(flag);
  
          return (keysVal &amp; flagVal) == flagVal;
      }
  </code></pre>
  
  <p>Just realized is a bad idea to check the way I was checking (<code>return (keys &amp; flag) != 0;</code>), because the <code>flag</code> parameter might be actually several flags and the common sense thing to do is return true only if <code>keys</code> contains all of them. Also, I wouldn't check for null values or even make sure they are the same type. I might <em>want</em> to use different types.</p>