2

我正在将 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");

并且根据选择的不同设置中的女巫“标签”将返回。有没有办法在 vb.NET 中做到这一点。我曾考虑为这些标签中的每一个创建一个枚举,但似乎它应该是一个更好的解决方案。有任何想法吗?

4

1 回答 1

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
于 2012-08-15T14:48:46.337 回答