I'm trying to write an abstract base class for read-only collections which implement IList
. Such a base class should implement the set-indexer to throw a NotSupportedException
, but leave the get-indexer as abstract. Does C# allow such a situation? Here's what I have so far:
public abstract class ReadOnlyList : IList {
public bool IsReadOnly { get { return true; } }
public object this[int index] {
get {
// there is nothing to put here! Ideally it would be left abstract.
throw new NotImplementedException();
}
set {
throw new NotSupportedException("The collection is read-only.");
}
}
// other members of IList ...
}
Ideally ReadOnlyList
would be able to implement the setter but leave the getter abstract. Is there any syntax which allows this?