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
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
namespace MyLibrary
{
[FlagsAttribute]
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
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
namespace MyLibrary
{
public enum Color // Compliant - no FlagsAttribute attribute
{
None = 0,
Red = 1,
Orange = 3,
Yellow = 4
}
[FlagsAttribute]
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)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]