If I have a method that requires a parameter that,
Count
propertyWhat should the type
Since IList
and IReadOnlyList
do not share any useful "ancestor", and if you don't want your method to accept any other type of parameter, the only thing you can do is provide two overloads.
If you decide that reusing codes is a top priority then you could have these overloads forward the call to a private
method that accepts IEnumerable
and uses LINQ in the manner Daniel suggests, in effect letting LINQ do the normalization at runtime.
However IMHO it would probably be better to just copy/paste the code once and just keep two independent overloads that differ on just the type of argument; I don't believe that micro-architecture of this scale offers anything tangible, and on the other hand it requires non-obvious maneuvers and is slower.