Ross Goddard Ross Goddard - 1 year ago 98 Question

Get the Integer value of an enumeration which is a generic

Here is the basic situation.

Public Class MyEnumClass(of T)
Public MyValue as T
End Class

This is vast oversimplification of the actual class, but basically I know that T is an enumeration (if it is not then there will be many other problems, and is a logical error made by the programmer)

Basically I want to get the underlying integer value of MyValue.

Using Cint or Ctype, does not work.

Answer Source

I was going to use a cool piece of reflection code but just a simple Convert.ToInt32 works great... Forgive my VB I'm a C# guy

Public Function GetEnumInt(Of T)(enumVal As T) As Integer
    Return Convert.ToInt32(enumVal)
End Function
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download