2012-08-15 73 views
2

我正在將Java程序翻譯爲vb.net,其中應用程序的設置由enum控制。藉助枚舉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中做到這一點。我曾想過爲這些TAG的每一個創建一個枚舉,但它似乎應該是更好的解決方案。 任何想法?

回答

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