diff --git a/Directory.Packages.props b/Directory.Packages.props
index 1c54ce00..d8b9644c 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -18,15 +18,18 @@
-
-
+
+
+
+
+
\ No newline at end of file
diff --git a/benchmarks/SmartEnum.Benchmarks/EqualsBenchmarks.cs b/benchmarks/SmartEnum.Benchmarks/EqualsBenchmarks.cs
index a24fa863..5ecf7d37 100644
--- a/benchmarks/SmartEnum.Benchmarks/EqualsBenchmarks.cs
+++ b/benchmarks/SmartEnum.Benchmarks/EqualsBenchmarks.cs
@@ -1,8 +1,10 @@
namespace Ardalis.SmartEnum.Benchmarks
{
using BenchmarkDotNet.Attributes;
+ using System.Diagnostics.CodeAnalysis;
[Config(typeof(Config))]
+ [SuppressMessage("Major Bug", "S1764:Identical expressions should not be used on both sides of operators", Justification = "")]
public class EqualsBenchmarks
{
////////////////////////////////////////////////////////////////////////////////
diff --git a/benchmarks/SmartEnum.Benchmarks/SerializationBenchmarks.cs b/benchmarks/SmartEnum.Benchmarks/SerializationBenchmarks.cs
index bda01166..15053f7d 100644
--- a/benchmarks/SmartEnum.Benchmarks/SerializationBenchmarks.cs
+++ b/benchmarks/SmartEnum.Benchmarks/SerializationBenchmarks.cs
@@ -1,5 +1,6 @@
namespace Ardalis.SmartEnum.Benchmarks
{
+ using System.Diagnostics.CodeAnalysis;
using System.IO;
using BenchmarkDotNet.Attributes;
@@ -68,6 +69,7 @@ public sealed class TestSmartEnumValueClass
static Stream valueProtoBufDeserializeStream;
[GlobalSetup]
+ [SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "")]
public void GlobalSetup()
{
global::Utf8Json.Resolvers.CompositeResolver.Register(
diff --git a/benchmarks/SmartEnum.Benchmarks/SwitchBenchmarks.cs b/benchmarks/SmartEnum.Benchmarks/SwitchBenchmarks.cs
index 2be5fa45..d655ddfb 100644
--- a/benchmarks/SmartEnum.Benchmarks/SwitchBenchmarks.cs
+++ b/benchmarks/SmartEnum.Benchmarks/SwitchBenchmarks.cs
@@ -1,9 +1,12 @@
namespace Ardalis.SmartEnum.Benchmarks
{
using System;
+ using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
[Config(typeof(Config))]
+ [SuppressMessage("Major Bug", "S2583:Conditionally executed code should be reachable", Justification = "")]
+ [SuppressMessage("Major Code Smell", "S112:General or reserved exceptions should never be thrown", Justification = "")]
public class SwitchBenchmarks
{
////////////////////////////////////////////////////////////////////////////////
diff --git a/benchmarks/SmartEnum.Benchmarks/TestEnums.cs b/benchmarks/SmartEnum.Benchmarks/TestEnums.cs
index c43c4464..e789c0c2 100644
--- a/benchmarks/SmartEnum.Benchmarks/TestEnums.cs
+++ b/benchmarks/SmartEnum.Benchmarks/TestEnums.cs
@@ -1,9 +1,12 @@
+using System.Diagnostics.CodeAnalysis;
+
namespace Ardalis.SmartEnum.Benchmarks
{
////////////////////////////////////////////////////////////////////////////////
// Enum
[global::ProtoBuf.ProtoContract]
+ [SuppressMessage("Minor Code Smell", "S2344:Enumeration type names should not have \"Flags\" or \"Enum\" suffixes", Justification = "")]
public enum TestEnum
{
[global::ProtoBuf.ProtoEnum]
diff --git a/src/SmartEnum.AutoFixture/SmartEnum.AutoFixture.csproj b/src/SmartEnum.AutoFixture/SmartEnum.AutoFixture.csproj
index 0f1cf9e9..18382a42 100644
--- a/src/SmartEnum.AutoFixture/SmartEnum.AutoFixture.csproj
+++ b/src/SmartEnum.AutoFixture/SmartEnum.AutoFixture.csproj
@@ -16,8 +16,6 @@
-
-
diff --git a/src/SmartEnum.Dapper/DapperSmartEnum.cs b/src/SmartEnum.Dapper/DapperSmartEnum.cs
index a4e5c710..b896ce80 100644
--- a/src/SmartEnum.Dapper/DapperSmartEnum.cs
+++ b/src/SmartEnum.Dapper/DapperSmartEnum.cs
@@ -1,6 +1,5 @@
namespace Ardalis.SmartEnum.Dapper
{
- //using global::Dapper;
using System;
///
diff --git a/src/SmartEnum.JsonNet/SmartEnum.JsonNet.csproj b/src/SmartEnum.JsonNet/SmartEnum.JsonNet.csproj
index 40996a94..3399a51b 100644
--- a/src/SmartEnum.JsonNet/SmartEnum.JsonNet.csproj
+++ b/src/SmartEnum.JsonNet/SmartEnum.JsonNet.csproj
@@ -1,4 +1,4 @@
-
+
Ardalis.SmartEnum.JsonNet
Ardalis.SmartEnum.JsonNet
@@ -15,8 +15,6 @@
-
-
diff --git a/src/SmartEnum.MessagePack/SmartEnum.MessagePack.csproj b/src/SmartEnum.MessagePack/SmartEnum.MessagePack.csproj
index 159f4cb0..38105c57 100644
--- a/src/SmartEnum.MessagePack/SmartEnum.MessagePack.csproj
+++ b/src/SmartEnum.MessagePack/SmartEnum.MessagePack.csproj
@@ -15,8 +15,6 @@
-
-
diff --git a/src/SmartEnum.ModelBinding/SmartEnumModelBinder.cs b/src/SmartEnum.ModelBinding/SmartEnumModelBinder.cs
index 9838af2d..08b92fae 100644
--- a/src/SmartEnum.ModelBinding/SmartEnumModelBinder.cs
+++ b/src/SmartEnum.ModelBinding/SmartEnumModelBinder.cs
@@ -36,14 +36,13 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
if (methodInfo.Name == "FromName")
{
ParameterInfo[] methodsParams = methodInfo.GetParameters();
- if (methodsParams.Length == 2)
+ if (methodsParams.Length == 2 &&
+ methodsParams[0].ParameterType == typeof(string) &&
+ methodsParams[1].ParameterType == typeof(bool))
{
- if (methodsParams[0].ParameterType == typeof(string) && methodsParams[1].ParameterType == typeof(bool))
- {
- var enumObj = methodInfo.Invoke(null, new object[] { enumKeyName, true });
- bindingContext.Result = ModelBindingResult.Success(enumObj);
- return Task.CompletedTask;
- }
+ var enumObj = methodInfo.Invoke(null, new object[] { enumKeyName, true });
+ bindingContext.Result = ModelBindingResult.Success(enumObj);
+ return Task.CompletedTask;
}
}
}
diff --git a/src/SmartEnum.ProtoBufNet/SmartEnum.ProtoBufNet.csproj b/src/SmartEnum.ProtoBufNet/SmartEnum.ProtoBufNet.csproj
index 2fc31bc4..dd1267d5 100644
--- a/src/SmartEnum.ProtoBufNet/SmartEnum.ProtoBufNet.csproj
+++ b/src/SmartEnum.ProtoBufNet/SmartEnum.ProtoBufNet.csproj
@@ -15,8 +15,6 @@
-
-
diff --git a/src/SmartEnum.SystemTextJson/SmartEnum.SystemTextJson.csproj b/src/SmartEnum.SystemTextJson/SmartEnum.SystemTextJson.csproj
index 5abf1caa..c4752c75 100644
--- a/src/SmartEnum.SystemTextJson/SmartEnum.SystemTextJson.csproj
+++ b/src/SmartEnum.SystemTextJson/SmartEnum.SystemTextJson.csproj
@@ -1,28 +1,26 @@
-
- Ardalis.SmartEnum.SystemTextJson
- Ardalis.SmartEnum.SystemTextJson
- System.Text.Json (de)serialization support for Ardalis.SmartEnum.
- System.Text.Json (de)serialization support for Ardalis.SmartEnum.
- MIT
- enum;smartenum;netstandard2.0;json;system.text.json;converter
- icon.png
- Updating to net7.
- Ardalis.SmartEnum.SystemTextJson
- Ardalis.SmartEnum.SystemTextJson
-
-
- bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml
-
-
-
-
-
-
-
-
-
-
-
-
+
+ Ardalis.SmartEnum.SystemTextJson
+ Ardalis.SmartEnum.SystemTextJson
+ System.Text.Json (de)serialization support for Ardalis.SmartEnum.
+ System.Text.Json (de)serialization support for Ardalis.SmartEnum.
+ MIT
+ enum;smartenum;netstandard2.0;json;system.text.json;converter
+ icon.png
+ Updating to net7.
+ Ardalis.SmartEnum.SystemTextJson
+ Ardalis.SmartEnum.SystemTextJson
+
+
+ bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml
+
+
+
+
+
+
+
+
+
+
diff --git a/src/SmartEnum/Exceptions/InvalidFlagEnumValueParseException.cs b/src/SmartEnum/Exceptions/InvalidFlagEnumValueParseException.cs
index 598fcdf8..e19fcc7b 100644
--- a/src/SmartEnum/Exceptions/InvalidFlagEnumValueParseException.cs
+++ b/src/SmartEnum/Exceptions/InvalidFlagEnumValueParseException.cs
@@ -1,11 +1,13 @@
using System;
+using System.Diagnostics.CodeAnalysis;
namespace Ardalis.SmartEnum.Exceptions
{
///
- ///
+ ///
///
[Serializable]
+ [SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "")]
public class InvalidFlagEnumValueParseException : Exception
{
///
@@ -16,7 +18,7 @@ public InvalidFlagEnumValueParseException() : base()
}
///
- /// Initializes a new instance of the class with a user specified error .
+ /// Initializes a new instance of the class with a user specified error .
///
/// The error message that explains the reason for the exception.
public InvalidFlagEnumValueParseException(string message) : base(message)
@@ -28,7 +30,7 @@ public InvalidFlagEnumValueParseException(string message) : base(message)
/// and a wrapped that is the cause of this exception.
///
/// The error message that explains the reason for the exception.
- /// The exception that is the cause of the current exception. If the parameter is not a null reference,
+ /// The exception that is the cause of the current exception. If the parameter is not a null reference,
/// the current exception is raised in a catch block that handles the inner exception.
public InvalidFlagEnumValueParseException(string message, Exception innerException) : base(message, innerException)
{
diff --git a/src/SmartEnum/Exceptions/NegativeValueArgumentException.cs b/src/SmartEnum/Exceptions/NegativeValueArgumentException.cs
index f4601051..cedd162d 100644
--- a/src/SmartEnum/Exceptions/NegativeValueArgumentException.cs
+++ b/src/SmartEnum/Exceptions/NegativeValueArgumentException.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Ardalis.SmartEnum.Exceptions
@@ -8,6 +9,7 @@ namespace Ardalis.SmartEnum.Exceptions
/// The exception that is thrown when a negative value is provided as an argument value.
///
[Serializable]
+ [SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "")]
public class NegativeValueArgumentException : ArgumentException
{
///
@@ -26,12 +28,12 @@ public NegativeValueArgumentException(string message) : base(message)
}
///
- /// Initializes a new instance of the class with a specified error message and
+ /// Initializes a new instance of the class with a specified error message and
/// a reference to the inner exception that is the cause of this exception.
///
/// The error message that explains the reason for the exception.
///
- /// The exception that is the cause of the current exception. If the parameter is not a null reference,
+ /// The exception that is the cause of the current exception. If the parameter is not a null reference,
/// the current exception is raised in a catch block that handles the inner exception.
///
public NegativeValueArgumentException(string message, Exception innerException) : base(message, innerException)
diff --git a/src/SmartEnum/Exceptions/SmartEnumNotFoundException.cs b/src/SmartEnum/Exceptions/SmartEnumNotFoundException.cs
index 497b2f69..0ec05d6f 100644
--- a/src/SmartEnum/Exceptions/SmartEnumNotFoundException.cs
+++ b/src/SmartEnum/Exceptions/SmartEnumNotFoundException.cs
@@ -1,11 +1,13 @@
namespace Ardalis.SmartEnum
{
using System;
+ using System.Diagnostics.CodeAnalysis;
///
/// The exception that is thrown when a item is not found.
///
[Serializable]
+ [SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "")]
public class SmartEnumNotFoundException : Exception
{
///
@@ -26,12 +28,12 @@ public SmartEnumNotFoundException(string message)
}
///
- /// Initializes a new instance of the class with a specified error message and
+ /// Initializes a new instance of the class with a specified error message and
/// a reference to the inner exception that is the cause of this exception.
///
/// The error message that explains the reason for the exception.
///
- /// The exception that is the cause of the current exception. If the parameter is not a null reference,
+ /// The exception that is the cause of the current exception. If the parameter is not a null reference,
/// the current exception is raised in a catch block that handles the inner exception.
///
public SmartEnumNotFoundException(string message, Exception innerException)
diff --git a/src/SmartEnum/Exceptions/SmartFlagEnumContainsNegativeValueException.cs b/src/SmartEnum/Exceptions/SmartFlagEnumContainsNegativeValueException.cs
index cf2bb681..0fe392c6 100644
--- a/src/SmartEnum/Exceptions/SmartFlagEnumContainsNegativeValueException.cs
+++ b/src/SmartEnum/Exceptions/SmartFlagEnumContainsNegativeValueException.cs
@@ -1,11 +1,13 @@
using System;
+using System.Diagnostics.CodeAnalysis;
namespace Ardalis.SmartEnum.Exceptions
{
///
- ///
+ ///
///
[Serializable]
+ [SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "")]
public class SmartFlagEnumContainsNegativeValueException : Exception
{
///
@@ -16,7 +18,7 @@ public SmartFlagEnumContainsNegativeValueException() : base()
}
///
- /// Initializes a new instance of the class with a user specified error .
+ /// Initializes a new instance of the class with a user specified error .
///
/// The error message that explains the reason for the exception.
public SmartFlagEnumContainsNegativeValueException(string message) : base(message)
@@ -28,7 +30,7 @@ public SmartFlagEnumContainsNegativeValueException(string message) : base(messag
/// and a wrapped that is the cause of this exception.
///
/// The error message that explains the reason for the exception.
- /// The exception that is the cause of the current exception. If the parameter is not a null reference,
+ /// The exception that is the cause of the current exception. If the parameter is not a null reference,
/// the current exception is raised in a catch block that handles the inner exception.
public SmartFlagEnumContainsNegativeValueException(string message, Exception innerException) : base(message, innerException)
{
diff --git a/src/SmartEnum/Exceptions/SmartFlagEnumDoesNotContainPowerOfTwoValuesException.cs b/src/SmartEnum/Exceptions/SmartFlagEnumDoesNotContainPowerOfTwoValuesException.cs
index aa9bbbd1..3f7cdee2 100644
--- a/src/SmartEnum/Exceptions/SmartFlagEnumDoesNotContainPowerOfTwoValuesException.cs
+++ b/src/SmartEnum/Exceptions/SmartFlagEnumDoesNotContainPowerOfTwoValuesException.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Ardalis.SmartEnum.Exceptions
@@ -8,6 +9,7 @@ namespace Ardalis.SmartEnum.Exceptions
/// The exception that is thrown when a does not contain consecutive power of two values.
///
[Serializable]
+ [SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "")]
public class SmartFlagEnumDoesNotContainPowerOfTwoValuesException : Exception
{
///
@@ -28,12 +30,12 @@ public SmartFlagEnumDoesNotContainPowerOfTwoValuesException(string message)
}
///
- /// Initializes a new instance of the class with a specified error message and
+ /// Initializes a new instance of the class with a specified error message and
/// a reference to the inner exception that is the cause of this exception.
///
/// The error message that explains the reason for the exception.
///
- /// The exception that is the cause of the current exception. If the parameter is not a null reference,
+ /// The exception that is the cause of the current exception. If the parameter is not a null reference,
/// the current exception is raised in a catch block that handles the inner exception.
///
public SmartFlagEnumDoesNotContainPowerOfTwoValuesException(string message, Exception innerException)
diff --git a/src/SmartEnum/SmartEnum.cs b/src/SmartEnum/SmartEnum.cs
index 1ff43a95..00b424d5 100644
--- a/src/SmartEnum/SmartEnum.cs
+++ b/src/SmartEnum/SmartEnum.cs
@@ -4,6 +4,7 @@ namespace Ardalis.SmartEnum
{
using System;
using System.Collections.Generic;
+ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
@@ -21,7 +22,7 @@ public abstract class SmartEnum :
where TEnum : SmartEnum
{
///
- ///
+ ///
///
///
///
@@ -94,7 +95,7 @@ private static IEqualityComparer GetValueComparer()
private readonly TValue _value;
///
- ///
+ ///
///
///
///
@@ -128,11 +129,11 @@ protected SmartEnum(string name, TValue value)
/// The name of the item to get.
/// true to ignore case during the comparison; otherwise, false.
///
- /// The item associated with the specified name.
+ /// The item associated with the specified name.
/// If the specified name is not found, throws a .
///
- /// is null.
- /// does not exist.
+ /// is null.
+ /// does not exist.
///
///
public static TEnum FromName(string name, bool ignoreCase = false)
@@ -160,12 +161,12 @@ TEnum FromName(Dictionary dictionary)
///
/// The name of the item to get.
///
- /// When this method returns, contains the item associated with the specified name, if the key is found;
+ /// When this method returns, contains the item associated with the specified name, if the key is found;
/// otherwise, null. This parameter is passed uninitialized.
///
/// true if the contains an item with the specified name; otherwise, false.
///
- /// is null.
+ /// is null.
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -178,12 +179,12 @@ public static bool TryFromName(string name, out TEnum result) =>
/// The name of the item to get.
/// true to ignore case during the comparison; otherwise, false.
///
- /// When this method returns, contains the item associated with the specified name, if the name is found;
+ /// When this method returns, contains the item associated with the specified name, if the name is found;
/// otherwise, null. This parameter is passed uninitialized.
///
/// true if the contains an item with the specified name; otherwise, false.
///
- /// is null.
+ /// is null.
///
///
public static bool TryFromName(string name, bool ignoreCase, out TEnum result)
@@ -208,9 +209,10 @@ public static bool TryFromName(string name, bool ignoreCase, out TEnum result)
/// The first item found that is associated with the specified value.
/// If the specified value is not found, throws a .
///
- /// does not exist.
+ /// does not exist.
///
///
+ [SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "")]
public static TEnum FromValue(TValue value)
{
TEnum result;
@@ -261,7 +263,7 @@ public static TEnum FromValue(TValue value, TEnum defaultValue)
///
/// The value of the item to get.
///
- /// When this method returns, contains the item associated with the specified value, if the value is found;
+ /// When this method returns, contains the item associated with the specified value, if the value is found;
/// otherwise, null. This parameter is passed uninitialized.
///
/// true if the contains an item with the specified name; otherwise, false.
@@ -280,14 +282,14 @@ public static bool TryFromValue(TValue value, out TEnum result)
}
///
- ///
+ ///
///
///
public override string ToString() =>
_name;
///
- ///
+ ///
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -295,7 +297,7 @@ public override int GetHashCode() =>
_value.GetHashCode();
///
- ///
+ ///
///
///
///
@@ -313,7 +315,7 @@ public virtual bool Equals(SmartEnum other)
if (Object.ReferenceEquals(this, other))
return true;
- // it's not same instance so
+ // it's not same instance so
// check if it's not null and is same value
if (other is null)
return false;
@@ -349,7 +351,7 @@ public SmartEnumThen When(IEnumerable> s
new SmartEnumThen(smartEnums.Contains(this), false, this);
///
- ///
+ ///
///
///
///
@@ -365,7 +367,7 @@ public SmartEnumThen When(IEnumerable> s
}
///
- ///
+ ///
///
///
///
@@ -384,7 +386,7 @@ public virtual int CompareTo(SmartEnum other) =>
_value.CompareTo(other._value);
///
- ///
+ ///
///
///
///
@@ -394,7 +396,7 @@ public virtual int CompareTo(SmartEnum other) =>
left.CompareTo(right) < 0;
///
- ///
+ ///
///
///
///
@@ -404,7 +406,7 @@ public virtual int CompareTo(SmartEnum other) =>
left.CompareTo(right) <= 0;
///
- ///
+ ///
///
///
///
@@ -414,7 +416,7 @@ public virtual int CompareTo(SmartEnum other) =>
left.CompareTo(right) > 0;
///
- ///
+ ///
///
///
///
@@ -424,7 +426,7 @@ public virtual int CompareTo(SmartEnum other) =>
left.CompareTo(right) >= 0;
///
- ///
+ ///
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -434,7 +436,7 @@ smartEnum is not null
: default;
///
- ///
+ ///
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/src/SmartEnum/SmartEnum.csproj b/src/SmartEnum/SmartEnum.csproj
index 43c176a6..69faf525 100644
--- a/src/SmartEnum/SmartEnum.csproj
+++ b/src/SmartEnum/SmartEnum.csproj
@@ -34,7 +34,7 @@
-
+
diff --git a/src/SmartEnum/SmartEnumNameAttribute.cs b/src/SmartEnum/SmartEnumNameAttribute.cs
index 2d609c9c..cbb2d88d 100644
--- a/src/SmartEnum/SmartEnumNameAttribute.cs
+++ b/src/SmartEnum/SmartEnumNameAttribute.cs
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
@@ -34,6 +35,7 @@ public class SmartEnumNameAttribute : ValidationAttribute
/// When is not a
/// or
///
+ [SuppressMessage("Major Bug", "S3343:Caller information parameters should come at the end of the parameter list", Justification = "")]
public SmartEnumNameAttribute(
Type smartEnumType,
[CallerMemberName] string propertyName = null,
@@ -53,7 +55,7 @@ public SmartEnumNameAttribute(
}
///
- ///
+ ///
///
///
///
diff --git a/src/SmartEnum/SmartFlagEngine.cs b/src/SmartEnum/SmartFlagEngine.cs
index 30b5478f..8ac50832 100644
--- a/src/SmartEnum/SmartFlagEngine.cs
+++ b/src/SmartEnum/SmartFlagEngine.cs
@@ -1,7 +1,8 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -29,6 +30,7 @@ protected SmartFlagEngine() { }
/// The value to retrieve.
/// an of from which to retrieve values.
///
+ [SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "")]
protected static IEnumerable GetFlagEnumValues(TValue value, IEnumerable allEnumList)
{
GuardAgainstNull(value);
@@ -184,6 +186,8 @@ private static bool IsPowerOfTwo(int input)
return false;
}
+ [SuppressMessage("Performance", "CA1826:Do not use Enumerable methods on indexable collections", Justification = "")]
+ [SuppressMessage("Minor Code Smell", "S6608:Prefer indexing instead of \"Enumerable\" methods on types implementing \"IList\"", Justification = "")]
private static int HighestFlagValue(IReadOnlyList enumList)
{
var highestIndex = enumList.Count - 1;
diff --git a/src/SmartEnum/SmartFlagEnum.cs b/src/SmartEnum/SmartFlagEnum.cs
index e76059d5..5448367a 100644
--- a/src/SmartEnum/SmartFlagEnum.cs
+++ b/src/SmartEnum/SmartFlagEnum.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
@@ -18,7 +19,7 @@ public abstract class SmartFlagEnum :
where TEnum : SmartFlagEnum
{
///
- ///
+ ///
///
///
///
@@ -91,7 +92,7 @@ private static IEnumerable GetAllOptions()
_value;
///
- ///
+ ///
///
///
///
@@ -113,10 +114,10 @@ protected SmartFlagEnum(string name, TValue value)
/// true to ignore case during the comparison; otherwise, false.
///
///
- /// The items associated with the specified .
+ /// The items associated with the specified .
///
- /// is null.
- /// does not exist.
+ /// is null.
+ /// does not exist.
public static IEnumerable FromName(string names, bool ignoreCase = false, bool deserialize = false)
{
if (String.IsNullOrEmpty(names))
@@ -142,12 +143,12 @@ IEnumerable FromName(Dictionary dictionary)
///
/// The names of the item/s to get.
///
- /// When this method returns, contains the item associated with the specified names, if the key is found;
+ /// When this method returns, contains the item associated with the specified names, if the key is found;
/// otherwise, null. This parameter is passed uninitialized.
///
/// true if the contains an item with the specified names; otherwise, false.
///
- /// is null.
+ /// is null.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryFromName(string names, out IEnumerable result) =>
TryFromName(names, false, out result);
@@ -158,12 +159,12 @@ public static bool TryFromName(string names, out IEnumerable result) =>
/// The names of the item/s to get.
/// true to ignore case during the comparison; otherwise, false.
///
- /// When this method returns, contains the items associated with the specified names, if any names are found;
+ /// When this method returns, contains the items associated with the specified names, if any names are found;
/// otherwise, null. This parameter is passed uninitialized.
///
/// true if the contains an item with the specified names; otherwise, false.
///
- /// is null.
+ /// is null.
public static bool TryFromName(string names, bool ignoreCase, out IEnumerable result)
{
if (String.IsNullOrEmpty(names))
@@ -182,7 +183,8 @@ public static bool TryFromName(string names, bool ignoreCase, out IEnumerable
/// An containing the item/s found.
///
- /// does not exist.
+ /// does not exist.
+ [SuppressMessage("Minor Code Smell", "S4136:Method overloads should be grouped together", Justification = "")]
public static IEnumerable FromValue(TValue value)
{
if (value == null)
@@ -199,24 +201,22 @@ public static IEnumerable FromValue(TValue value)
///
/// Attempts to retrieve a single by value. (Bypasses all Flag behaviour)
///
- /// does not exist.
+ /// does not exist.
///
///
public static TEnum DeserializeValue(TValue value)
{
+ //todo we should not be calling get options for each deserialization. Perhaps move it to a lazy field _enumOptions.
var enumList = GetAllOptions();
- foreach (var smartFlagEnum in enumList)
+ var returnValue = enumList.FirstOrDefault(x => x.Value.Equals(value));
+
+ if (returnValue == null)
{
- if (smartFlagEnum.Value.Equals(value))
- {
- return smartFlagEnum;
- }
+ ThrowHelper.ThrowValueNotFoundException(value);
}
- ThrowHelper.ThrowValueNotFoundException(value);
-
- return null;
+ return returnValue;
}
///
@@ -242,7 +242,7 @@ public static IEnumerable FromValue(TValue value, IEnumerable defa
///
/// The value of the item/s to get.
///
- /// When this method returns, contains the IEnumerable of item/s associated with the specified value, if any value is found;
+ /// When this method returns, contains the IEnumerable of item/s associated with the specified value, if any value is found;
/// otherwise, null. This parameter is passed uninitialized.
///
/// true if the contains any items with the specified names; otherwise, false.
@@ -285,7 +285,7 @@ public static string FromValueToString(TValue value)
///
/// The value of the item/s to get.
///
- /// When this method returns, contains the string representation associated with the specified value, if any value is found;
+ /// When this method returns, contains the string representation associated with the specified value, if any value is found;
/// otherwise, returns null.
/// A comma delineated series of enum names as a
public static bool TryFromValueToString(TValue value, out string result)
@@ -300,15 +300,16 @@ public static bool TryFromValueToString(TValue value, out string result)
return true;
}
+ [SuppressMessage("Minor Code Smell", "S6608:Prefer indexing instead of \"Enumerable\" methods on types implementing \"IList\"", Justification = "")]
private static string FormatEnumListString(IEnumerable enumInputList)
{
var enumList = enumInputList.ToList();
var sb = new StringBuilder();
- foreach (var smartFlagEnum in enumList)
+ foreach (var smartFlagEnum in enumList.Select(x => x.Name))
{
- sb.Append(smartFlagEnum.Name);
- if (enumList.Last().Name != smartFlagEnum.Name && enumList.Count > 1)
+ sb.Append(smartFlagEnum);
+ if (enumList.Last().Name != smartFlagEnum && enumList.Count > 1)
{
sb.Append(", ");
}
@@ -333,7 +334,7 @@ public override int GetHashCode() =>
_value.GetHashCode();
///
- ///
+ ///
///
///
///
@@ -351,7 +352,7 @@ public virtual bool Equals(SmartFlagEnum other)
if (Object.ReferenceEquals(this, other))
return true;
- // it's not same instance so
+ // it's not same instance so
// check if it's not null and is same value
if (other is null)
return false;
@@ -387,7 +388,7 @@ public SmartEnumThen When(IEnumerable(smartEnums.Contains(this), false, this);
///
- ///
+ ///
///
///
///
@@ -403,7 +404,7 @@ public SmartEnumThen When(IEnumerable
- ///
+ ///
///
///
///
@@ -422,7 +423,7 @@ public virtual int CompareTo(SmartFlagEnum other) =>
_value.CompareTo(other._value);
///
- ///
+ ///
///
///
///
@@ -432,7 +433,7 @@ public virtual int CompareTo(SmartFlagEnum other) =>
left.CompareTo(right) < 0;
///
- ///
+ ///
///
///
///
@@ -442,7 +443,7 @@ public virtual int CompareTo(SmartFlagEnum other) =>
left.CompareTo(right) <= 0;
///
- ///
+ ///
///
///
///
@@ -452,7 +453,7 @@ public virtual int CompareTo(SmartFlagEnum other) =>
left.CompareTo(right) > 0;
///
- ///
+ ///
///
///
///
@@ -462,7 +463,7 @@ public virtual int CompareTo(SmartFlagEnum other) =>
left.CompareTo(right) >= 0;
///
- ///
+ ///
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -470,7 +471,7 @@ public static implicit operator TValue(SmartFlagEnum smartFlagEnu
smartFlagEnum._value;
///
- ///
+ ///
///
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]