Possible Duplicates:
Anyone know a good workaround for the lack of an enum generic constraint?
Create Generic method constraining T to an Enum
Is is possible to limit the generic type parameter [I don't know if that's the right name] to an Enum
?
For example how do I do something like this?
//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<T> GetValues<T>(T value) where T : System.Enum
{
return Enum.GetValues(value.GetType());
}
Update
I eventually used Jon Skeet's Unconstrained Melody for that purpose. Thanks to you all for your contributions.