Skip to content

Commit

Permalink
Fix: Resolve ambiguity in TryGetElementType() for Mono runtime (#3395)
Browse files Browse the repository at this point in the history
  • Loading branch information
medhatiwari committed Dec 5, 2024
1 parent c6fb5e2 commit 6cb9612
Showing 1 changed file with 17 additions and 13 deletions.
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

0 comments on commit 6cb9612

Please sign in to comment.