From a373176e275512db85b63f0ee9a5b4126a6c1010 Mon Sep 17 00:00:00 2001 From: Nikolay Pozdnichenko Date: Mon, 18 Mar 2024 13:50:09 +0600 Subject: [PATCH] Some small refactorings --- Libiada.Core/Core/IBaseObject.cs | 8 +++++++- Libiada.Core/DataTransformers/HighOrderFactory.cs | 3 ++- Libiada.Core/Extensions/EnumExtensions.cs | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Libiada.Core/Core/IBaseObject.cs b/Libiada.Core/Core/IBaseObject.cs index e831abaf..24686e21 100644 --- a/Libiada.Core/Core/IBaseObject.cs +++ b/Libiada.Core/Core/IBaseObject.cs @@ -21,7 +21,7 @@ public interface IBaseObject /// Object to compare to. /// /// - /// true of objects are equal and false otherwise. + /// True if objects are equal and false otherwise. /// bool Equals(object other); @@ -33,4 +33,10 @@ public interface IBaseObject /// The . /// int GetHashCode(); + + /// + /// Converts to + /// + /// + string ToString(); } diff --git a/Libiada.Core/DataTransformers/HighOrderFactory.cs b/Libiada.Core/DataTransformers/HighOrderFactory.cs index 80da1356..ee93a8b4 100644 --- a/Libiada.Core/DataTransformers/HighOrderFactory.cs +++ b/Libiada.Core/DataTransformers/HighOrderFactory.cs @@ -26,7 +26,8 @@ public static class HighOrderFactory /// public static Chain Create(Chain source, Link link) { - if (link != Link.Start && link != Link.End && link != Link.CycleEnd && link != Link.CycleStart) + Link[] applicableLinks = [Link.Start, Link.End, Link.CycleEnd, Link.CycleStart]; + if (!applicableLinks.Contains(link)) { throw new ArgumentException("Unknown or inapplicable link", nameof(link)); } diff --git a/Libiada.Core/Extensions/EnumExtensions.cs b/Libiada.Core/Extensions/EnumExtensions.cs index 37d3a7c7..6f676d30 100644 --- a/Libiada.Core/Extensions/EnumExtensions.cs +++ b/Libiada.Core/Extensions/EnumExtensions.cs @@ -37,7 +37,7 @@ public static string GetDisplayValue(this T value) where T : struct, ICompara var fieldInfo = type.GetField(value.ToString(CultureInfo.InvariantCulture)); - var descriptionAttributes = fieldInfo.GetCustomAttributes(typeof(DisplayAttribute), false) as DisplayAttribute[]; + var descriptionAttributes = fieldInfo?.GetCustomAttributes(typeof(DisplayAttribute), false) as DisplayAttribute[]; if (descriptionAttributes == null) { @@ -57,12 +57,12 @@ public static string GetDisplayValue(this T value) where T : struct, ICompara /// Enum type. /// /// - /// The . + /// The or if value is not found. /// /// /// Thrown if type argument is not enum. /// - public static string GetName(this T value) where T : struct, IComparable, IFormattable, IConvertible + public static string? GetName(this T value) where T : struct, IComparable, IFormattable, IConvertible { Type type = typeof(T);