You are out of luck here. IList<T> doesn’t implement IReadOnlyList<T>. List<T> does implement both interfaces, but I think that’s not what you want.
However, you can use LINQ:
- The
Count()extension method internally checks whether the instance in fact is a collection and then uses theCountproperty. - The
ElementAt()extension method internally checks whether the instance in fact is a list and than uses the indexer.