title: How to limit a generic type parameter to System.Enum
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/7244/anyone-know-a-good-workaround-for-the-lack-of-an-enum-generic-constraint">Anyone know a good workaround for the lack of an enum generic constraint?</a><br>
    <a href="https://stackoverflow.com/questions/79126/create-generic-method-constraining-t-to-an-enum">Create Generic method constraining T to an Enum</a>  </p>
  </blockquote>
  
  
  
  <p>Is is possible to limit the generic type parameter [I don't know if that's the right name] to an <code>Enum</code>?</p>
  
  <p>For example how do I do something like this?</p>
  
  <pre><code>//VB.NET
  Function GetValues(Of T As System.Enum)(ByVal value As T) As IEnumerable(Of T)
      Return [Enum].GetValues(value.GetType)
  End Function
  
  //C#
  public IEnumerable&lt;T&gt; GetValues&lt;T&gt;(T value) where T : System.Enum
  {
      return Enum.GetValues(value.GetType());
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>I eventually used Jon Skeet's <a href="http://code.google.com/p/unconstrained-melody/" rel="noreferrer" title="Google Code: Unconstrained Melody">Unconstrained Melody</a> for that purpose. Thanks to you all for your contributions.</p>