File tree Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ details about the cause of the failure
31
31
- Fix non-delegate types incorrectly appearing as callable.
32
32
- Indexers can now be used with interface objects
33
33
- Fixed a bug where indexers could not be used if they were inherited
34
+ - Made it possible to use ` __len__ ` also on ` ICollection<> ` interface objects
34
35
35
36
## [ 2.5.0] [ ] - 2020-06-14
36
37
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ public static bool CanAssgin(Type clrType)
36
36
{
37
37
return true ;
38
38
}
39
+ if ( clrType . IsInterface && clrType . IsGenericType && clrType . GetGenericTypeDefinition ( ) == typeof ( ICollection < > ) )
40
+ {
41
+ return true ;
42
+ }
39
43
return false ;
40
44
}
41
45
Original file line number Diff line number Diff line change @@ -47,3 +47,17 @@ def test_custom_generic_collection_explicit___len__():
47
47
s .Add (1 )
48
48
s .Add (10 )
49
49
assert len (s ) == 2
50
+
51
+ def test_len_through_interface_generic ():
52
+ """Test __len__ for ICollection<T>"""
53
+ import System .Collections .Generic
54
+ l = System .Collections .Generic .List [int ]()
55
+ coll = System .Collections .Generic .ICollection [int ](l )
56
+ assert len (coll ) == 0
57
+
58
+ def test_len_through_interface ():
59
+ """Test __len__ for ICollection"""
60
+ import System .Collections
61
+ l = System .Collections .ArrayList ()
62
+ coll = System .Collections .ICollection (l )
63
+ assert len (coll ) == 0
You can’t perform that action at this time.
0 commit comments