Convert Enum value to English using a function

I am trying to write a function that converts an enum value to English.

I can easily make this line a line, but a function would be the best solution.

For example:

Public Enum UpdateEnum
    No_Update_Required = 0
    WebSite_Needs_Update = 1
    Internal_Needs_Update = 2
End Enum

Public Enum EmailComparisonEnum
    WebSiteEmailRequiresUpdate = 0
    InternalEmailRequireUpdate = 1
    NoUpdateRequired = 2
End Enum

      

Now I can easily convert the numeric value of an enum to English using the following code:

EmailStatus = [Enum].GetName(GetType(EmailComparisonEnum), EnumVariable)

      

Let's say EnumVariable = 2. Then "NoUpdateRequired" will be assigned to the email status.

Since doing this line by line, every time I need to convert an enum to English it looks cumbersome and (important) I have several types of enums; I want to create a function for this.

My current function:

Private Function ConvertEnumValueToEnglish(EnumType As Type, Value As Integer) As String
    ConvertEnumValueToEnglish = [Enum].GetName(GetType(EnumType), Value)
End Function

      

But so far I cannot figure out how to do it.

+3


source to share





All Articles