On Mon, 13 Oct 2003 00:25:17 +0930, "Shayne H"
<shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote:
What is the best way to enumerate a grouping of strings?
The way I have been doing it is:
Public Enum PlatformID
Unknown
Win16
Win32
Win32NT
WinCE
End Enum
I'm guessing you're not talking about System.PlatformID.
Private Shared sPlatform() As String = { _
"Unknown", _
"Microsoft Windows 16-bit", _
"Microsoft Windows 32-bit", _
"Microsoft Windows NT 32-bit", _
"Microsoft Windows CE"}
I don't suppose this is what you're after...
Dim oPlatformID As PlatformID
oPlatformID = PlatformID.Win32
MsgBox( oPlatformID.ToString() )
If internationalisation is an issue, then you should use resources.
(Unlikely, as "Microsoft Windows CE" is the same in most languages)
If you require spaces (etc.) to be in the name, the best way is to
implement a singleton class that wraps up a StringDictionary
(initialised in its constructor) - see below.
And if you fancy being a pedant, you should implement a Platform class
instead of an enum, a PlatformCollection of some sorts (an inherited
HybridDictionary is a good one), a PlatformFactory object to serialise
the objects from resources (and implement the GetCurrentPlatform
method)... and be sure to implement IComparable and IEnumerable on the
Platform and PlatformCollection respectively. Infact, inherit your own
IPlatformEnumerable so that you can iterate though any other ADT
collections you decide to implement. Ooh! And don't forget to
implement an IPlatform interface in case anyone wants to alter the
implementation of a Platform... ;]
More seriously, the following allows for future extension (and the
model can be applied to other things... for your reference)
Public Class PlatformFactory
Private Shared mPlatformMap As HybridDictionary
Shared Sub New()
mPlatformMap = New HybridDictionary()
mPlatformMap.Add(PlatformID.Unknown, "Unknown")
mPlatformMap.Add(PlatformID.Win16, "Microsoft Windows 16-bit")
' etc...
End Sub
Public Shared Function GetName(ByVal oPlatformID As PlatformID) _
As String
Return mPlatformMap(oPlatformID)
End Function
End Class
Rgds,