silverblatt
Member
- Joined
- Sep 28, 2021
- Messages
- 5
- Programming Experience
- 10+
I have a need to retrieve the name associated with a given value in a particular enum (the enum is named FormMode). I can retrieve the name using this code:
This works but the syntax strikes me as a little cumbersome, so I wrote a wrapper function to make my code easier to understand:
This also works, but now I want to generalize the function so that it will do the same job for ANY enum. I've tried this:
but it produces the error "Type 'EN' is not defined." with EN underlined in red in the RETURN statement. I get the same error when I change the parameter type from System.Enum to System.Type.
How can I pass the specific enum as a parameter in such a way that it can be used by the GetType method?
VB.NET:
[Enum].GetName(GetType(FormMode), enum_item_value)
This works but the syntax strikes me as a little cumbersome, so I wrote a wrapper function to make my code easier to understand:
VB.NET:
Public Function GetItemName(ItemValue As Int32) As String
Return [Enum].GetName(GetType(FormMode), ItemValue)
End Function
This also works, but now I want to generalize the function so that it will do the same job for ANY enum. I've tried this:
VB.NET:
Public Function GetItemName2(EN As System.Enum, ItemValue As Int32) As String
Return [Enum].GetName(GetType(EN), ItemValue)
End Function
but it produces the error "Type 'EN' is not defined." with EN underlined in red in the RETURN statement. I get the same error when I change the parameter type from System.Enum to System.Type.
How can I pass the specific enum as a parameter in such a way that it can be used by the GetType method?