From 363ffee738d4753850e7705c286f34eacceb173d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 26 Mar 2026 11:30:40 -0400 Subject: [PATCH] AttributeHelper code was only ever used in converters --- SabreTools.Metadata/AttributeHelper.cs | 47 ------------------------- SabreTools.Metadata/Converters.cs | 48 ++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 49 deletions(-) delete mode 100644 SabreTools.Metadata/AttributeHelper.cs diff --git a/SabreTools.Metadata/AttributeHelper.cs b/SabreTools.Metadata/AttributeHelper.cs deleted file mode 100644 index b74209c5..00000000 --- a/SabreTools.Metadata/AttributeHelper.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; - -namespace SabreTools.Metadata -{ - public static class AttributeHelper - { - /// - /// Get the MappingAttribute from a supported value - /// - /// Value to use - /// MappingAttribute attached to the value - public static MappingAttribute? GetMappingAttribute(T? value) - { - // Null value in, null value out - if (value is null) - return null; - - // Current enumeration type - var enumType = typeof(T); - if (Nullable.GetUnderlyingType(enumType) is not null) - enumType = Nullable.GetUnderlyingType(enumType); - - // If the value returns a null on ToString, just return null - string? valueStr = value.ToString(); - if (string.IsNullOrEmpty(valueStr)) - return null; - - // Get the member info array - var memberInfos = enumType?.GetMember(valueStr); - if (memberInfos is null) - return null; - - // Get the enum value info from the array, if possible - var enumValueMemberInfo = Array.Find(memberInfos, m => m.DeclaringType == enumType); - if (enumValueMemberInfo is null) - return null; - - // Try to get the relevant attribute - var attributes = enumValueMemberInfo.GetCustomAttributes(typeof(MappingAttribute), true); - if (attributes is null || attributes.Length == 0) - return null; - - // Return the first attribute, if possible - return (MappingAttribute?)attributes[0]; - } - } -} diff --git a/SabreTools.Metadata/Converters.cs b/SabreTools.Metadata/Converters.cs index 27f8eed3..3a65d59c 100644 --- a/SabreTools.Metadata/Converters.cs +++ b/SabreTools.Metadata/Converters.cs @@ -43,7 +43,7 @@ namespace SabreTools.Metadata continue; // Try to get the mapping attribute - MappingAttribute? attr = AttributeHelper.GetMappingAttribute(value); + MappingAttribute? attr = GetMappingAttribute(value); if (attr?.Mappings is null || attr.Mappings.Length == 0) continue; @@ -106,7 +106,7 @@ namespace SabreTools.Metadata continue; // Try to get the mapping attribute - MappingAttribute? attr = AttributeHelper.GetMappingAttribute(value); + MappingAttribute? attr = GetMappingAttribute(value); if (attr?.Mappings is null || attr.Mappings.Length == 0) continue; @@ -128,5 +128,49 @@ namespace SabreTools.Metadata } #endregion + + #region Helpers + + /// + /// Get the MappingAttribute from a supported value + /// + /// Value to use + /// MappingAttribute attached to the value + internal static MappingAttribute? GetMappingAttribute(T? value) + { + // Null value in, null value out + if (value is null) + return null; + + // Current enumeration type + var enumType = typeof(T); + if (Nullable.GetUnderlyingType(enumType) is not null) + enumType = Nullable.GetUnderlyingType(enumType); + + // If the value returns a null on ToString, just return null + string? valueStr = value.ToString(); + if (string.IsNullOrEmpty(valueStr)) + return null; + + // Get the member info array + var memberInfos = enumType?.GetMember(valueStr); + if (memberInfos is null) + return null; + + // Get the enum value info from the array, if possible + var enumValueMemberInfo = Array.Find(memberInfos, m => m.DeclaringType == enumType); + if (enumValueMemberInfo is null) + return null; + + // Try to get the relevant attribute + var attributes = enumValueMemberInfo.GetCustomAttributes(typeof(MappingAttribute), true); + if (attributes is null || attributes.Length == 0) + return null; + + // Return the first attribute, if possible + return (MappingAttribute?)attributes[0]; + } + + #endregion } }