I am implementing a custom collection implementation that can either be readonly or non-readonly; that is, all the methods that change the collection call a function that is the moral equivalent of:
private void ThrowIfReadOnly() {
if (this.isReadOnly)
throw new SomeException("Cannot modify a readonly collection.");
}
I am not sure which of NotSupportedException
or InvalidOperationException
I should use in that case.
ObjectDisposedException
instead ofInvalidOperationException
even though it is an invalid operation. – Sarah