Remove System.Collection.NonGeneric from SqlClient contract #6527
Conversation
Change SqlBulkCopyColumnMappingCollection to no longer inherit from CollectionBase in the SqlClient contract, along the lines of other collections like X509CertificateCollection, XmlArrayItemAttributes, XmlAnyElementAttributes, etc.
Changes SqlBulkCopyColumnMappingCollection to implement IList directly instead of deriving from CollectionBase, using List<T> as the private backing collection. Includes tests to verify the behavior remains the same as when the implementation came from CollectionBase.
@justinvp Thanks for the changes |
} | ||
} | ||
|
||
private IList NonGenericList => _list; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the NonGenericList
needed?
In the code the _list
is being referenced using NonGenericList
and _list
member. Can we have this being referenced consistently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to call some of the explicitly implemented non-generic collection interface members on List<T>
and having this property is a convenient way to do that. Otherwise, we'd have to cast the List<T>
to the non-generic interfaces at the callsites, e.g.:
void ICollection.CopyTo(Array array, int index) => ((ICollection)_list).CopyTo(array, index);
We did the same thing in X509CertificateCollection
to avoid the casts at the callsites.
Lines 247 to 250 in c20fcbe
private IList NonGenericList | |
{ | |
get { return _list; } | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK 👍
LGTM. |
Remove System.Collection.NonGeneric from SqlClient contract
…ionbase Remove System.Collection.NonGeneric from SqlClient contract Commit migrated from dotnet/corefx@36f5cf3
A new dependency on
System.Collections.NonGeneric
was recently added toSystem.Data.SqlClient
in #6396 as part of exposingSqlBulkCopyColumnMappingCollection
, which derives fromCollectionBase
.This PR is made up of two commits:
SqlBulkCopyColumnMappingCollection
to derive fromIList
directly instead ofCollectionBase
. This is consistent with other collections in CoreFX that derive fromCollectionBase
in the full framework (e.g.X509CertificateCollection
[manual],XmlArrayItemAttributes
[manual],XmlAnyElementAttributes
[manual], etc.).SqlBulkCopyColumnMappingCollection
implementation to implementIList
directly instead of deriving fromCollectionBase
. Tests are included to verify the behavior remains the same as when the implementation came fromCollectionBase
(I also ran these tests on the full framework).There are two additional related changes I'd like to address in separate PRs:
System.Collections.NonGeneric
from theSqlClient
implementation. There are a few remaining uses ofArrayList
andHashtable
inSqlClient
that can be compatibly changed to no longer depend on the legacy collections. I plan to submit a separate PR that does this.SqlBulkCopyColumnMappingCollection
to useList<object>
as the backing collection, to maintain the same behavior as when it derived fromCollectionBase
. However, it'd make more sense to strongly type it asList<SqlBulkCopyColumnMapping>
as this collection is only intended to holdSqlBulkCopyColumnMapping
objects. I didn't do that as part of this PR because it would change the behavior of some of the non-genericIList
members (for the better, IMO). For example,IList.Add(object)
currently allows adding an object of any type, even though it should really throw if the object isn'tSqlBulkCopyColumnMapping
(we've made similar changes to other collections in CoreFX that previously derived fromCollectionBase
in the full framework likeX509CertificateCollection
, changing it to useList<X509Certificate>
as the backing collection in Cleanup and harden X509Certificate collections #2824).Fixes #6406.
cc: @saurabh500