How can I get Enum description from its value?
I can get the description from the name using:
Public Shared Function GetEnumDescription(ByVal EnumConstant As [Enum]) As String
Dim fi As FieldInfo = EnumConstant.GetType().GetField(EnumConstant.ToString())
Dim attr() As DescriptionAttribute = _
DirectCast(fi.GetCustomAttributes(GetType(DescriptionAttribute), _
False), DescriptionAttribute())
If attr.Length > 0 Then
Return attr(0).Description
Else
Return EnumConstant.ToString()
End If
End Function
But I cant figure out how to pass a variable name to this function. I've tried things like
GetEnumDescription([Enum].GetName(GetType(myEnum), 2)))
but nothing I've tried is correct.