I favor an approach like EG's however with a little bit more since i'm utterly spoiled by the intuitiveness of the VS IDE. You can get his shared properties approach to behave in the IDE as a true enum like the Color and Pen classes:-
The key to making this work is the completionlist tag above the class declarations. Notice that ive also made a couple of adjustments to EG's example. First I have the properties return a DefaultMasks object instead of a string so we can declare a variable as DefaultMasks without provoking a type mismatch. Ive also overriden the assignment operator so you can assign an object of type DefaultMasks directly to a string as:-vbnet Code:
''' <completionlist cref="DefaultMasks"/> Public Class DefaultMasks Private _mask As String Private Sub New(ByVal mask As String) _mask = mask End Sub Public Shared ReadOnly Property PhoneNumber() As DefaultMasks Get Return New DefaultMasks("(999)000-0000") End Get End Property Public Shared ReadOnly Property ZipCode() As DefaultMasks Get Return New DefaultMasks("00000-9999") End Get End Property Public Shared Widening Operator CType(ByVal dm As DefaultMasks) As String Return dm._mask End Operator End Class
However, it may be better to override the ToString method of the class to make this assignment more explicit and obvious to anyone reading the code.vbnet Code:
Dim dm As DefaultMasks = DefaultMasks.PhoneNumber Dim s As String = dm




Reply With Quote