diff --git a/src/Shared/SharedTypeExtensions.cs b/src/Shared/SharedTypeExtensions.cs index 6965d22cb..c94f43efb 100644 --- a/src/Shared/SharedTypeExtensions.cs +++ b/src/Shared/SharedTypeExtensions.cs @@ -215,23 +215,27 @@ public static Type GetSequenceType(this Type type) return null; } - var types = GetGenericTypeImplementations(type, interfaceOrBaseType); + var types = GetGenericTypeImplementations(type, interfaceOrBaseType); - Type? singleImplementation = null; - foreach (var implementation in types) - { - if (singleImplementation is null) - { - singleImplementation = implementation; - } - else + if (!types.Any()) + { + return null; + } + + if (type.IsArray) + { + var elementType = type.GetElementType(); + if (elementType != null) { - singleImplementation = null; - break; + var arrayCompatible = types.FirstOrDefault(t => t.GenericTypeArguments.Contains(elementType)); + if (arrayCompatible != null) + { + return arrayCompatible.GenericTypeArguments.First(); + } } - } + } - return singleImplementation?.GenericTypeArguments.FirstOrDefault(); + return types.First().GenericTypeArguments.FirstOrDefault(); } #nullable disable