I am very confused with the Array.IList implementation. All of the methods
are private which hardly seems to be fulfilling the IList contract... If I
cast an array then IList methods (e.g. Contains()) work correctly for arrays
of rank 1. Where is the code that check the rank of arrays and
allows/disallows IList.Contains() accordingly? I am using Reflector to
examine the framework code and I cannot find this functionality. Any clues?
Thanks,
Andy
>All of the methods
>are private which hardly seems to be fulfilling the IList contract...
Why not? Interfaces don't specify which accessibility the implementing
method must have - private is fine.
>If I
>cast an array then IList methods (e.g. Contains()) work correctly for arrays
>of rank 1. Where is the code that check the rank of arrays and
>allows/disallows IList.Contains() accordingly?
Array::System.Collections.IList.Contains(object) calls
Array::IndexOf(Array, object), which in turn calls
Array::IndexOf(Array, object, int, int). There you'll find code that
checks the Rank and throws an exception if it's != 1.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
A J Le Couteur Bisson - 15 Jul 2004 14:15 GMT
> >All of the methods
> >are private which hardly seems to be fulfilling the IList contract...
>
> Why not? Interfaces don't specify which accessibility the implementing
> method must have - private is fine.
Thanks for the prompt response. Clearly the contract offered by interfaces
*can* be rather less useful than I supposed. (I am reminded of a past
employer
which, under contract to make 'a delivery', delivered an empty box!**)
I am still puzzled as to why these methods are private. What harm could
result
from making them public?
if((myArray as IList).Contains(3))
doesn't seem any clearer or more appropriate than
if(myArray.Contains(3))
Thanks,
Andy
** A very large company that ought to know better...
Mattias Sj?gren - 20 Jul 2004 09:50 GMT
Andy,
>I am still puzzled as to why these methods are private. What harm could
>result from making them public?
I don't know why they decided to implement IList privately. Perhaps
because the interface is only partially supported (the Add, Insert,
Remove and RemoveAt methods will throw).
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.