diff --git a/SabreTools.Core/ConcurrentListExtensions.cs b/SabreTools.Core/ConcurrentListExtensions.cs index 4150bdb8..031729c3 100644 --- a/SabreTools.Core/ConcurrentListExtensions.cs +++ b/SabreTools.Core/ConcurrentListExtensions.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; namespace SabreTools.Core { @@ -8,7 +7,7 @@ namespace SabreTools.Core public static ConcurrentList ToConcurrentList(this IEnumerable values) { var list = new ConcurrentList(); - list.SetInternalList(values.ToList()); + list.SetInternalList([.. values]); return list; } } diff --git a/SabreTools.Core/Tools/Converters.cs b/SabreTools.Core/Tools/Converters.cs index fb5949b3..f1892b63 100644 --- a/SabreTools.Core/Tools/Converters.cs +++ b/SabreTools.Core/Tools/Converters.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using SabreTools.Logging; namespace SabreTools.Core.Tools @@ -87,7 +86,7 @@ namespace SabreTools.Core.Tools // Try to get the mapping attribute MappingAttribute? attr = AttributeHelper.GetAttribute(value); - if (attr?.Mappings == null || !attr.Mappings.Any()) + if (attr?.Mappings == null || attr.Mappings.Length == 0) continue; // Loop through the mappings and add each @@ -170,7 +169,7 @@ namespace SabreTools.Core.Tools // Try to get the mapping attribute MappingAttribute? attr = AttributeHelper.GetAttribute(value); - if (attr?.Mappings == null || !attr.Mappings.Any()) + if (attr?.Mappings == null || attr.Mappings.Length == 0) continue; // Use either the first or second item in the list diff --git a/SabreTools.Core/Tools/NumberHelper.cs b/SabreTools.Core/Tools/NumberHelper.cs index 26a6f574..3637fe13 100644 --- a/SabreTools.Core/Tools/NumberHelper.cs +++ b/SabreTools.Core/Tools/NumberHelper.cs @@ -141,25 +141,23 @@ namespace SabreTools.Core.Tools if (DetermineMultiplier(value) > 1) value = value.TrimEnd(['k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ']); -#if NETFRAMEWORK || NETCOREAPP3_1 || NET5_0 - return value.All(c => char.IsNumber(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || c == '.' || c == ','); -#elif NET7_0_OR_GREATER +#if NET7_0_OR_GREATER return value.All(c => char.IsAsciiHexDigit(c) || c == '.' || c == ','); #else return value.All(c => c.IsAsciiHexDigit() || c == '.' || c == ','); #endif } -#if NET6_0 +#if NETFRAMEWORK || NETCOREAPP3_1 || NET5_0 || NET6_0 /// /// Indicates whether a character is categorized as an ASCII hexademical digit. /// /// The character to evaluate. /// true if c is a hexademical digit; otherwise, false. /// This method determines whether the character is in the range '0' through '9', inclusive, 'A' through 'F', inclusive, or 'a' through 'f', inclusive. - private static bool IsAsciiHexDigit(this char c) + internal static bool IsAsciiHexDigit(this char c) { - return c switch + return char.ToLowerInvariant(c) switch { '0' => true, '1' => true, @@ -172,17 +170,11 @@ namespace SabreTools.Core.Tools '8' => true, '9' => true, 'a' => true, - 'A' => true, 'b' => true, - 'B' => true, 'c' => true, - 'C' => true, 'd' => true, - 'D' => true, 'e' => true, - 'E' => true, 'f' => true, - 'F' => true, _ => false, }; } diff --git a/SabreTools.Core/Tools/TextHelper.cs b/SabreTools.Core/Tools/TextHelper.cs index f6354344..9e60ac3b 100644 --- a/SabreTools.Core/Tools/TextHelper.cs +++ b/SabreTools.Core/Tools/TextHelper.cs @@ -124,7 +124,12 @@ namespace SabreTools.Core.Tools return input; List invalidPath = [.. Path.GetInvalidPathChars()]; - return new string(input.Where(c => !invalidPath.Contains(c)).ToArray()); + foreach (char invalid in Path.GetInvalidPathChars()) + { + input = input!.Replace(invalid.ToString(), string.Empty); + } + + return input; } /// @@ -223,7 +228,11 @@ namespace SabreTools.Core.Tools hash = hash.ToLowerInvariant(); // Otherwise, make sure that every character is a proper match - if (hash.Any(c => (c < '0' || c > '9') && (c < 'a' || c > 'f'))) +#if NET7_0_OR_GREATER + if (hash.Any(c => char.IsAsciiHexDigit(c))) +#else + if (hash.Any(c => c.IsAsciiHexDigit())) +#endif hash = string.Empty; return hash; diff --git a/SabreTools.Core/Tools/TypeHelper.cs b/SabreTools.Core/Tools/TypeHelper.cs index ac871978..53fca007 100644 --- a/SabreTools.Core/Tools/TypeHelper.cs +++ b/SabreTools.Core/Tools/TypeHelper.cs @@ -53,11 +53,11 @@ namespace SabreTools.Core.Tools List assemblyTypes = []; try { - assemblyTypes = assembly.GetTypes().ToList(); + assemblyTypes = [.. assembly.GetTypes()]; } catch (ReflectionTypeLoadException rtle) { - assemblyTypes = rtle.Types.Where(t => t != null)!.ToList(); + assemblyTypes = [.. rtle.Types.Where(t => t != null)]; } // Loop through all types @@ -92,11 +92,11 @@ namespace SabreTools.Core.Tools List assemblyTypes = []; try { - assemblyTypes = assembly.GetTypes().ToList(); + assemblyTypes = [.. assembly.GetTypes()]; } catch (ReflectionTypeLoadException rtle) { - assemblyTypes = rtle.Types.Where(t => t != null)!.ToList(); + assemblyTypes = [.. rtle.Types.Where(t => t != null)]; } // Loop through all types