Workaround for MS CA1008 code analysis rule: enumerations must be null

I am working on a .NET 4.0 / C # project. I have included some basic code analysis rules for my project. I ended up in CA1008. I fully understand why the CA1008 is necessary.

The software I work with communicates with other devices. These devices are customizable. The configuration is stored in the internal EEPROM. One of the configurations is AlarmType, in the EEPROM, which can have a value from 1 to 11. I defined the type of alarm as follows:

public enum AlarmType
{
    Type1 = 1,
    Type2 = 2,
    Type3 = 3,
    // ...
    Type10 = 10,
    Type11 = 11
}

When configuring devices, I allow the user to select one of the types of alarms by selecting the alarm values ​​with Enum.GetValues(). When checking the value in EEPROM, this requirement looks like the value is from 1 to 11, and then displays the name of the alarm, otherwise read it Type1.

Visual Studio 2010 issues a warning that it AlarmTypeshould have a value of zero. I do not want to add this because it will (1) violate the definition AlarmType( AlarmTypecannot be None) and (2) an additional check will be necessary to exclude the option Nonewhen listing enum values ​​for presentation to the user.

Instead of suppressing CA1008, what can I do as a workaround? Did I do something wrong in my design?

+3
2

AlarmType 0. .

AlaramType alarmType;

AlarmType 0. , , .

, (1) AlarmType (AlarmType None) (2) , None enum .

. AlarmType 0 , , , , AlarmType . 0 , AlarmType 0, .

, 0 Invalid None -, , enum .

, , , attribute.

+5

, , , , 0 , EEPROM ,

  public static int AsEeprom(this AlarmType etype)
    {
      return ((int)etype) + 1;
    }
+1

All Articles