If we look to the following code:
[Flags] // FP: this is a flags enum
public enum SvoFeatures
{
Field = /*...............*/ 0x00001,
GetHashCode = /*.........*/ 0x00002,
IsEmpty = /*.............*/ 0x00004,
IsUnknown = /*...........*/ 0x00008,
IEquatable = /*..........*/ 0x00010,
EqualsSvo = /*...........*/ 0x00020,
ISerializable = /*.......*/ 0x00080,
IXmlSerializable = /*....*/ 0x00100,
IJsonSerializable = /*...*/ 0x00200,
IFormattable = /*........*/ 0x00400,
IComparable = /*.........*/ 0x00800,
ComparisonOperators = /*.*/ 0x01000,
Parsing = /*.............*/ 0x02000,
Validation = /*..........*/ 0x04000,
All = /*.................*/ 0x07FFF,
Structure = Field | IsEmpty | IsUnknown,
EqualsSvoAndGetHashCode = EqualsSvo | GetHashCode,
IsEmptyOrUnknown = IsEmpty | IsUnknown,
Default = All ^ ComparisonOperators ^ Validation,
Continuous = All ^ IsEmpty ^ IsUnknown ^ Validation,
Utf8 = /*................*/ 0x08000,
}
Reported by SonarAnalyzer.CSharp v10.7.0.110445
Than S4070 states that this is a none-flags enum. It does so because All
(which in this case does contain all except the last one, this is on purpose) is not a base2 value. If All
is removed, or defined as an or operation of all the previous 14 values, the rule would be satisfied. I would argue that in this case having an or on 14 values is not making things easier to read, and that this should be a false positive.
Note that if I change the value of All
to 0x0FFFF
, containing (actually all) values, the rule is also not satisified.