Take the community feedback survey now.

Non-flags enums should not be used in bitwise operations

Vote:
 

This is related to EPiServer.DataAccess.SaveAction not being annotated with [Flags] but is used for bitwise operations. Can we request to update it in next version?

Enumerations are commonly used to identify distinct elements from a set of values.

However, they can also serve as bit flags, enabling bitwise operations to combine multiple elements within a single value.

// Saturday = 0b00100000, Sunday = 0b01000000, weekend = 0b01100000
var weekend = Days.Saturday | Days.Sunday;  // Combining elements

When enumerations are used as bit flags, it is considered good practice to annotate the enum type with the FlagsAttribute:

enum Permissions { None = 0, Read = 1, Write = 2, Execute = 4 } // ...
var x = Permissions.Read | Permissions.Write; // Noncompliant: enum is not annotated with [Flags]

The FlagsAttribute explicitly marks an enumeration as bit flags, making it clear that it uses bit fields and is intended to be used as flags.

[Flags]
enum Permissions { None = 0, Read = 1, Write = 2, Execute = 4 } // ...
var x = Permissions.Read | Permissions.Write; // Compliant: enum is annotated with [Flags]

Additionally, adding the FlagsAttribute to the enumeration enable a better string representation when using the Enum.ToString method.

 

 

#339867
Edited, Aug 04, 2025 15:33
Graham Carr - Aug 05, 2025 7:13
If you are looking for a new feature to be added, you can do so at the Optimizely feedback site https://feedback.optimizely.com/
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.