Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource committed Oct 18, 2023
1 parent edf475a commit 8618a9b
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,18 @@ protected override void Initialize(SonarAnalysisContext context) =>
uint x => (BigInteger)x,
long x => (BigInteger)x,
ulong x => (BigInteger)x,
// this is a safeguard for the case when the enum is defined with a base type that is not currently supported by the compiler
var x when BigInteger.TryParse(x.ToString(), out var value) => value,
_ => null
}
: null;

private static bool IsValidFlagValue(BigInteger? enumValue, IEnumerable<BigInteger> allValues) =>
enumValue.HasValue && (IsZeroOrPowerOfTwo(enumValue.Value) || IsCombinationOfOtherValues(enumValue.Value, allValues));
enumValue.HasValue
&& (IsZeroOrPowerOfTwo(enumValue.Value)
|| IsCombinationOfOtherValues(enumValue.Value, allValues));

private static bool IsZeroOrPowerOfTwo(BigInteger value) =>
value.IsZero
|| (value.Sign == -1
? BigInteger.Multiply(value, -1).IsPowerOfTwo
: value.IsPowerOfTwo);
|| BigInteger.Abs(value).IsPowerOfTwo;

private static bool IsCombinationOfOtherValues(BigInteger value, IEnumerable<BigInteger> otherValues)
{
Expand Down

0 comments on commit 8618a9b

Please sign in to comment.