-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have HashSet<T> implement ICollection #23605
Comments
|
@sharwell You mean as opposed to |
@weitzhandler It's the same as the issue with defining an extension method on both An example of this is how people define |
This is similar in break-ability to https://github.com/dotnet/corefx/issues/23578, so my concerns there are echoed here: I don't think that being able to have a shared interface with the Count property is enough of a convenience to justify the breaks that this would incur. Because of the required breaking changes, it would be very unlikely that we would be able to push a change this large through the API review process without a huge number of people that wanted it. |
@ianhays |
The breaks are still there, though. The breaks come from introducing a new parent interface to HashSet; whether that is ICountable from #23337 or ICollection doesn't matter all that much. |
Then implement it (or a different 'countable' interface) explicitly.
Goal is to mutualize the `Count` property with some other collection types.
[EDIT] Remove email artifacts by @karelz
|
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of the experimental issue cleanup initiative we are currently trialing in a limited number of areas. Please share any feedback you might have in the linked issue. |
This issue will now be closed since it had been marked |
Motive
The
ICollection
(non-generic) interface, is a pathway to getting theCount
property of a collection in a non-generic way. This is very common in converters or some other types that take in any object and has to deal with it differently if it's a collection.Most common collections in .NET (
List<T>
,Dictionary<TKey, TValue>
,Collection<T>
, also implementICollection
, so it falls through the 'countable' criteria.However, the
HashSet<T>
class doesn't.So as explained in #23337, in order to obtain the
Count
of aHashSet<T>
, we'll have to use reflection if we don't knowT
at compile time (for example we have anobject
typed variable that we know it contains aHashSet<T>
, butT
can be anything, and is irrelevant to be able to get the count.Suggestion
I'd prefer seeing this issue addressed as it should be in the first place, which is having a non-generic middle interface that signifies the
Count
property, but meanwhile, having theHashSet<T>
implementICollection
will bring theHashSet<T>
to this countable group as well, even as a temporary solution.Things to consider
ICountable
, we have another class to take care of before getting rid of theICollection
part, if we want to.[EDIT] Fixed code link by @karelz
The text was updated successfully, but these errors were encountered: