In the CoreFx issue (https://github.com/dotnet/corefx/issues/1182) was the idea to do explicit check whether IReadOnlyCollection<T> interface is supported. But it was rejected due to the slow casting to a variant generic interface. According to my tests it is ~20 times slower than casting to non-variant.
Source code of the test: CastToInterfaceTest.cs
Test results:
| Cast From |
Cast To |
Is Variant |
Total time (ms) |
List<int> |
ICollection<int> |
false |
560 |
List<double> |
ICollection<int> |
false |
1290 |
Thread |
IReadOnlyCollection<int> |
true |
9713 |
List<int> |
IReadOnlyCollection<int> |
true |
21988 |
List<double> |
IReadOnlyCollection<int> |
true |
24294 |
It would be great to see some improvements here.