Enum Storage should be Int32

Rule ND2206 .NET Framework Usage / System

Enumerations store constants as System.Int32 by default. Changing the underlying type is rarely necessary or recommended: smaller types bring no significant performance improvement. If needed, use CLS-compliant integral types (Byte, Int16, Int32, Int64). Matches enumerations whose underlying type is not System.Int32.

How to fix

Use Int32 unless size or compatibility issues exist; Int64 if values don't fit, Byte or Int16 if backward compatibility requires it.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Enum Storage should be Int32</Name>
// <Id>ND2206:EnumStorageShouldBeInt32</Id>

warnif count > 0 from f in JustMyCode.Fields where 
   f.ParentType.IsEnumeration &&
   f.Name == @"value__" && 
   f.FieldType != null &&
   f.SizeOfInst > 0 && f.SizeOfInst < 4 &&
  !f.IsThirdParty
select new { 
   f, 
   f.SizeOfInst, 
   f.FieldType,
   Debt = 7.ToMinutes().ToDebt(),
   Severity = Severity.Medium
}

//<Expl>
// The *{0}* should be *Int32* and not the *{2}*. 
// Using a data type smaller than *Int32* doesn't result 
// in a significant performance improvement.
//</Expl>

//<Desc>
// Enumerations store constants as **System.Int32** by default. Changing the
// underlying type is rarely necessary or recommended: smaller types bring
// no significant performance improvement. If needed, use CLS-compliant
// integral types (*Byte*, *Int16*, *Int32*, *Int64*). Matches enumerations
// whose underlying type is not *System.Int32*.
//</Desc>

//<HowToFix>
// Use *Int32* unless size or compatibility issues exist; *Int64* if values
// don't fit, *Byte* or *Int16* if backward compatibility requires it.
//</HowToFix>

.NET Framework Usage / System: all 12 items