title: How to check if an object is an Enum
body: <p>I have a SQL query builder method:</p>
  
  <pre><code>public static string PreprocessSQL(string sql, params object[] args) 
  </code></pre>
  
  <p>Provided that the sql parameter is "String.Format friendly", this method loops through the params and plugs them into the query string, doing whatever needs to be done based on the type of the argument - convert a null to string "NULL", surround a string with single quotes, etc.</p>
  
  <p>Now the problem is with enums. I need a logic that checks if the type of current  args[i] is Enum, and if so, convert it to int. How to do this check? My first guess, for some reason, doesn't work:</p>
  
  <pre><code>if(args[i].GetType() == typeof(Enum)) {
      converted.Add((int)args[i]);
  }
  </code></pre>
  
  <p>The above condition apparently gets evaluated as false.</p>
  
  <p>My enum class is:</p>
  
  <pre><code>public enum Priority {
      Low,
      Normal,
      High
  }
  </code></pre>
  
  <p>If a pass a value of Priorty.Normal to this method, I figured the "value" is Normal, and the type of that value is Priority, which autmatically inherits from Enum, so I'm done. Turns out it's not that simple, and from what I can tell, it looks like the type of the value Normal is actually Priority.Normal</p>
  
  <p>Now I could explicitly check for all the enums I'm using in my project, it's only 2 classes actually, but would that even work? </p>
  
  <pre><code>if(args[i].GetType() == typeof(Priority)) { ... }
  </code></pre>
  
  <p>I mean, if type of args[i] is Priority.Normal, this would too evaluate as false.</p>
  
  <p>How do I check an unknown <code>object o</code> has the type of a enumeration class?</p>