From 8f2a85908724a064055c2b183b700cf0a5714eef Mon Sep 17 00:00:00 2001 From: Phil Scott Date: Wed, 20 Nov 2024 10:48:19 -0500 Subject: [PATCH] Fallback to using GetConverter if GetIntrinsicConverter doesn't find one. --- src/Spectre.Console/Internal/TypeConverterHelper.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Spectre.Console/Internal/TypeConverterHelper.cs b/src/Spectre.Console/Internal/TypeConverterHelper.cs index 6828c7c..da08d2b 100644 --- a/src/Spectre.Console/Internal/TypeConverterHelper.cs +++ b/src/Spectre.Console/Internal/TypeConverterHelper.cs @@ -82,12 +82,17 @@ internal static class TypeConverterHelper [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Feature switches are not currently supported in the analyzer")] static TypeConverter? GetConverter() { - if (!IsGetConverterSupported) + if (IsGetConverterSupported) { - return GetIntrinsicConverter(typeof(T)); + // Spectre.Console.TypeConverterHelper.IsGetConverterSupported has been set so + // fallback to original behavior + return TypeDescriptor.GetConverter(typeof(T)); } - return TypeDescriptor.GetConverter(typeof(T)); + // otherwise try and use the intrinsic converter. if we can't find one, then + // try and use GetConverter. + var intrinsicConverter = GetIntrinsicConverter(typeof(T)); + return intrinsicConverter ?? TypeDescriptor.GetConverter(typeof(T)); } }