Standard: Collection<T> and ObservableCollection<T> do not support ranges

Created on 27 Feb 2019  路  6Comments  路  Source: dotnet/standard

This is taken directly from https://github.com/dotnet/corefx/issues/10752 [by @robertmclaws]

This API change is already approved in .netcore (tentatively scheduled for 3.0), and I think it's equally as important to be available in .netstandard

    // Adds a range to the end of the collection.
    // Raises CollectionChanged (NotifyCollectionChangedAction.Add)
    public void AddRange(IEnumerable<T> collection) => InsertItemsRange(0, collection);

    // Inserts a range
    // Raises CollectionChanged (NotifyCollectionChangedAction.Add)
    public void InsertRange(int index, IEnumerable<T> collection) => InsertItemsRange(index, collection);

    // Removes a range.
    // Raises CollectionChanged (NotifyCollectionChangedAction.Remove)
    public void RemoveRange(int index, int count) => RemoveItemsRange(index, count);

    // Will allow to replace a range with fewer, equal, or more items.
    // Raises CollectionChanged (NotifyCollectionChangedAction.Replace)
    public void ReplaceRange(int index, int count, IEnumerable<T> collection)
    {
         RemoveItemsRange(index, count);
         InsertItemsRange(index, collection);
    }

    #region virtual methods
    protected virtual void InsertItemsRange(int index, IEnumerable<T> collection);
    protected virtual void RemoveItemsRange(int index, int count);
    #endregion

Please see the linked issue for the full discussion.

I'm assuming it would land here and the appropriate shims would be created, however I don't know enough about netstandard to actually draw up the PR.

netstandard-api

Most helpful comment

@terrajobst the .NET Core PR dotnet/corefx#35772 has been merged which was the last remaining outstanding work to get this feature into .NET Core.

What do we need to do to get this into .NET Strandard

All 6 comments

I'm so into this! @terrajobst please please please please

I just created an issue on the mono project so we get it added there as well. https://github.com/mono/mono/issues/13265

If this makes it into. NET Core soon, we can add it here.

@terrajobst the .NET Core PR dotnet/corefx#35772 has been merged which was the last remaining outstanding work to get this feature into .NET Core.

What do we need to do to get this into .NET Strandard

What do we need to do to get this into .NET Strandard

Nothing. I just submitted the PR. Members are by default included in the next version of the standard.

Such great news! Thanks @terrajobst

Was this page helpful?
0 / 5 - 0 ratings