Skip to content

Commit 6d2a502

Browse files
committed
Improve ReadOnlyObservableGroupedCollection<TKey, TValue> constructors
1 parent 684a650 commit 6d2a502

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

CommunityToolkit.Mvvm/Collections/ReadOnlyObservableGroupedCollection{TKey,TValue}.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Collections.Generic;
76
using System.Collections.ObjectModel;
87
using System.Collections.Specialized;
98
using System.Diagnostics;
@@ -23,18 +22,18 @@ public sealed class ReadOnlyObservableGroupedCollection<TKey, TValue> : ReadOnly
2322
/// Initializes a new instance of the <see cref="ReadOnlyObservableGroupedCollection{TKey, TValue}"/> class.
2423
/// </summary>
2524
/// <param name="collection">The source collection to wrap.</param>
26-
public ReadOnlyObservableGroupedCollection(ObservableGroupedCollection<TKey, TValue> collection)
27-
: this(collection.Select(static g => new ReadOnlyObservableGroup<TKey, TValue>(g)))
25+
public ReadOnlyObservableGroupedCollection(ObservableCollection<ObservableGroup<TKey, TValue>> collection)
26+
: base(new ObservableCollection<ReadOnlyObservableGroup<TKey, TValue>>(collection.Select(static g => new ReadOnlyObservableGroup<TKey, TValue>(g))))
2827
{
29-
((INotifyCollectionChanged)collection).CollectionChanged += OnSourceCollectionChanged;
28+
collection.CollectionChanged += OnSourceCollectionChanged;
3029
}
3130

3231
/// <summary>
3332
/// Initializes a new instance of the <see cref="ReadOnlyObservableGroupedCollection{TKey, TValue}"/> class.
3433
/// </summary>
35-
/// <param name="collection">The initial data to add in the grouped collection.</param>
36-
public ReadOnlyObservableGroupedCollection(IEnumerable<ReadOnlyObservableGroup<TKey, TValue>> collection)
37-
: base(new ObservableCollection<ReadOnlyObservableGroup<TKey, TValue>>(collection))
34+
/// <param name="collection">The source collection to wrap.</param>
35+
public ReadOnlyObservableGroupedCollection(ObservableCollection<ReadOnlyObservableGroup<TKey, TValue>> collection)
36+
: base(collection)
3837
{
3938
}
4039

0 commit comments

Comments
 (0)