I have an ICollection<T>
called foos
in my class which I want to expose as read-only (see this question). I see that the interface defines a property .IsReadOnly
, which seems appropriate... My question is this: how do I make it obvious to the consumer of the class that foos
is read-only?
I don't want to rely on them remembering to query .IsReadOnly
before trying a not-implemented method such as .Add()
. Ideally I would like to expose foos
as a ReadOnlyCollection<T>
, but it does not implement IList<T>
. Should I expose foo
via a method called eg. GetReadOnlyFooCollection
rather than via a property? If so, would this not confuse someone who then expects a ReadOnlyCollection<T>
?
Edit: C# 2.0, so no extension methods like ToList()
available...