Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Resolve ambiguity in TryGetElementType() for Mono runtime (#3395) #3399

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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