2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
This rule raises an issue when an externally visible enumeration is marked with ``++FlagsAttribute++`` and one, or more, of its values is not a power of 2 or a combination of the other defined values.
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
namespace MyLibrary
{
2023-04-06 16:18:18 +02:00
[Flags]
2021-04-28 16:49:39 +02:00
public enum Color // Noncompliant, Orange is neither a power of two, nor a combination of any of the defined values
{
None = 0,
Red = 1,
Orange = 3,
Yellow = 4
}
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
namespace MyLibrary
{
2023-04-06 16:18:18 +02:00
public enum Color // Compliant - no FlagsAttribute
2021-04-28 16:49:39 +02:00
{
None = 0,
Red = 1,
Orange = 3,
Yellow = 4
}
2023-04-06 16:18:18 +02:00
[Flags]
2021-04-28 16:49:39 +02:00
public enum Days
{
None = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 4,
Thursday = 8,
Friday = 16,
All = Monday| Tuesday | Wednesday | Thursday | Friday // Compliant - combination of other values
}
}
----
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Remove the "FlagsAttribute" from this enum.
=== Highlighting
Primary: Enum declaration
Secondaries: Enum values that are raising the issue
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]