FxCop: CA1033 - Implementing Microsoft ReadOnlyCollection violates this?

If you look at the code for a read-only collection, it does not have an Add method, but instead defines a method ICollection<T>.Add(T Value)(implementing an explicit interface).

When I did something similar with my ReadOnlyDictionary class, FxCop 10 complains that I am violating CA1033 .

public class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
{
    //CA1033 ERROR
    void IDictionary<TKey, TValue>.Add(TKey, TValue) { //Throw Exception }
}

public class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
{
    //NO CA1033 ERROR
    Add(TKey, TValue) { //Throw Exception }
}

ReadOnlyCollectionClass:

public class ReadOnlyCollection<T> : ICollection<T>
{
    void ICollection<T>.Add(T item) { //Throw Exception }
}

So is this a false positive? Is the Microsoft base code bad? What gives?

+5
source share
3 answers

Microsoft " " FxCop StyleCop. , ; BCL , - .NET .

, . , "". , . , LSP. "", () .

+5

. , , Add .

, / IList[<T>] , .

.

+1

- , . , ReadOnlyCollection . , , mscorlib SuppressMessage, , .

.NET Framework ReadOnlyDictionary, . , (System.Dynamic.Utils.ReadOnlyDictionary) "".

+1
source

All Articles