I have a list of rather meaningless codes that I'm processing with a VB.NET Windows application. For the business logic I'm writing to process those codes, I'd like to use meaningful constants (like ServiceNotCovered
or MemberNotEligible
) instead of the original codes (like "SNCV"
and "MNEL"
).
As far as I can tell, Enums can only map to numeric values, not to strings. So the best I've been able to come up with is a static class that exposes the constants as static readonly string fields that are internally set equal to the code values, as follows.
Public Class MyClass
private _reasonCode as String()
Public Property ReasonCode() As String
'Getter and Setter...
End Property
Public Class ReasonCodeEnum
Private Sub New()
End Sub
Public Shared ReadOnly ServiceNotCovered As String = "SNCV"
Public Shared ReadOnly MemberNotEligible As String = "MNEL"
'And so forth...
End Class
End Class
'Calling method
Public Sub ProcessInput()
Dim obj As New MyClass()
Select Case obj.ReasonCode
Case MyClass.ReasonCodeEnum.ServiceNotCovered
'Do one thing
Case MyClass.ReasonCodeEnum.MemberNotEligible
'Do something different
'Other enum value cases and default
End Select
End Sub
In the example above, it would be nice if I could define MyClass.ReasonCode
as having type ReasonCodeEnum
, but then I'd have to make ReasonCodeEnum
a nonstatic class and give it a way of setting and returning a value.
What I'm wondering is whether there's a way to use the built-in Enum functionality to do what I'm doing, or if not, are there any standard design patterns for this type of thing.