2013-02-14 38 views
5

我有這些枚舉:爲什麼Resharper認爲這些枚舉從未被使用?

private enum FontSizeType 
    { 
     XSmall, //9 
     Small, //12 
     Medium, //18 
     Large, //24 
     XLarge, //36 
     XXLarge //47 
    } 

    private enum AlignOptions 
    { 
     Left, 
     Center, 
     Right 
    } 

    private enum ValueType 
    { 
     Text, 
     Barcode 
    } 

而且ReSharper的檢查告訴我,所有的人都認爲「枚舉成員‘XSMALL’[等]從未使用過」

但我使用他們在我的組合盒子,就像這樣:

comboBoxType1.DataSource = Enum.GetNames(typeof(ValueType)); 

......那爲什麼Resharper被騙了?或者是?

+2

ReSharper的不「看」 FontSizeType.XSmall'的'直接使用(等)爲您的數據綁定_whole_枚舉。 – Oded 2013-02-14 21:47:15

回答

6

ReSharper不檢測隱式用法。你可以使用[UsedImplicitly]來告訴它你的類型成員是隱式使用的,然後它應該停止抱怨。

爲了在代碼中使用UsedImplicitlyAttribute,您應該包含對JetBrains.Annotations.dll的引用,或者在項目中包含一些複製粘貼的源代碼,有關詳細信息,請參見http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Annotations_in_Source_Code.html

您應該在每個枚舉值上添加[UsedImplicitly]。

+0

嘗試這樣的: [UsedImplicitly] 私人枚舉值類型 { 文本, 條碼 } ......我得到的,「類型或命名空間名稱‘UsedImplicitlyAttribute’找不到(是否缺少using指令或裝配參考?)「 – 2013-02-15 16:10:53

+0

@ClayShannon請查看更新的答案。 – 2013-02-15 17:39:55

+0

謝謝,但這樣我的源代碼就不那麼晦澀了,我只會「在這種情況下與Resharper的手指搖擺。 – 2013-02-15 17:48:57

2

您可以也使用這個指令禁用投訴本身: [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum ComplianceStatus { Notcompliant, Unknown, Warning, Compliant, Pendingrestart, Pendinglogoff }