Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Resharper think that these enums are never used?

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?

like image 218
B. Clay Shannon-B. Crow Raven Avatar asked Feb 14 '13 21:02

B. Clay Shannon-B. Crow Raven


2 Answers

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.

like image 107
Dmitry Osinovskiy Avatar answered Oct 14 '22 03:10

Dmitry Osinovskiy


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 }

like image 34
nohwnd Avatar answered Oct 14 '22 02:10

nohwnd