Why does Resharper think that these enums are never used?
Asked Answered
N

2

6

I have these enums:

    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
    }

And Resharper's inspection tells me about all of them that "Enum member 'XSmall' [etc.] is never used"

Yet I am using them in my combo boxes, like so:

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

...so why is Resharper fooled? Or is it?

Narcho answered 14/2, 2013 at 21:41 Comment(1)
Resharper doesn't "see" a direct usage of FontSizeType.XSmall (etc...) as you are databinding the whole enum.Mandatory
H
7

ReSharper doesn't detect implicit usages. You can use [UsedImplicitly] to tell it that your type member is used implicitly, and then it should stop complaining.

In order to use UsedImplicitlyAttribute in your code, you should either include reference to JetBrains.Annotations.dll or include some copy-pasted source code in your project, see http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Annotations_in_Source_Code.html for details.

You should add [UsedImplicitly] on each enum value.

Heeled answered 15/2, 2013 at 7:46 Comment(2)
Trying this: [UsedImplicitly] private enum ValueType { Text, Barcode } ...I get, "The type or namespace name 'UsedImplicitlyAttribute' could not be found (are you missing a using directive or an assembly reference?)"Narcho
Thanks, but rather than murky up my source that way, I'll just "live with" Resharper's finger-wagging in this instance.Narcho
A
2

You can as well disable the complaints itself by using this directive: [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum ComplianceStatus { Notcompliant, Unknown, Warning, Compliant, Pendingrestart, Pendinglogoff }

Asthenosphere answered 11/3, 2015 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.