8000 Add mp_length slot for .NET classes implementing ICollection/ICollection<T> by slide · Pull Request #994 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Add mp_length slot for .NET classes implementing ICollection/ICollection<T> #994

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

Merged
merged 10 commits into from
Dec 16, 2019
Prev Previous commit
Next Next commit
Update based on feedback
  • Loading branch information
slide committed Nov 25, 2019
commit 8f49346e2d80b72e23c6e233cebbd40e60906eda
11 changes: 2 additions & 9 deletions src/runtime/slots/mp_length.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,8 @@ public static int mp_length(IntPtr ob)
return (int)p.GetValue(co.inst, null);
}

// finally look for things that implement the interfaces explicitly
var iface = clrType.GetInterface(nameof(ICollection));
if(iface != null)
{
p = iface.GetProperty(nameof(ICollection.Count));
return (int)p.GetValue(co.inst, null);
}

iface = clrType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>));
// finally look for things that implement the interface explicitly
var iface = clrType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>));
if (iface != null)
{
p = iface.GetProperty(nameof(ICollection<int>.Count));
Expand Down
0