Fallback to using GetConverter if GetIntrinsicConverter doesn't find one.

This commit is contained in:
Phil Scott 2024-11-20 10:48:19 -05:00 committed by Patrik Svensson
parent 2be8e8da4e
commit 8f2a859087

View File

@ -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));
}
}