在enum VB.NET的帮助下获取设置

时间:2012-08-15 14:33:47

标签: java .net vb.net enums

我正在将Java程序翻译成vb.net,其中应用程序中的设置由枚举控制。

    private enum SmsTagRule {
    //      KEYWORD   DOMAIN    BusinessClass  PREFIX  SEARCHNAME   SEARCHPARAM  SENDEMAIL  KEYWORDS...
    BAG_TAG("BagTag", "BagTag", "FoundBagTag", "b", "SearchBagTag", "490_TagNumber", true, "BagTag"),
    SKI_TAG("SkiTag", "SkiTag", "FoundSkiTag", "a", "SearchSki", "518_LabelNo", false, "SkiTag", "ski"),
    PC_TAG("PcTag", "ds", "FoundPC", "", "SearchPcTag", "585_LabelNo", false, "pc");

依赖于女巫" TAG"在选择的不同设置中返回。在vb.NET中有没有办法做到这一点。我曾考虑过为这些TAG中的每一个创建一个枚举,但似乎它应该是一个更好的解决方案。 任何想法?

1 个答案:

答案 0 :(得分:2)

继续并创建代表您的设置的自定义类型:

Class TagRule

    Public Shared BAG = new TagRule("BagTag", "BagTag", "FoundBagTag", ...)
    Public Shared Ski = new TagRule("SkiTag", "SkiTag", "FoundSkiTag", ...)
    ...

    Dim _keyword As String
    Public Property Keyword as String
        Public Get
            return _keyword         
        End 
        Private Set
            _keyword = value
        End
    End Property

    ...

    Private Sub New(keyword as String, domain as String, businessclass as String, ...)
        _keyword = keyword
        _domain = domain
        ....
    End Sub

End Class

你可以像这样使用它:

Dim setting As TagRule = Nothing

If somecondition Then
    setting = TagRule.Ski
Else
    setting = TagRule.BAG
End If

Dim keyword = setting.Keyword
Dim domain = setting.Domain