Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/Shared/SharedTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading