// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace CommunityToolkit.Common.Collections;
///
/// A read-only observable group. It associates a to a .
///
/// The type of the group key.
/// The type of the items in the collection.
public sealed class ReadOnlyObservableGroup : ReadOnlyObservableCollection, IGrouping, IReadOnlyObservableGroup
where TKey : notnull
{
///
/// Initializes a new instance of the class.
///
/// The key of the group.
/// The collection of items to add in the group.
public ReadOnlyObservableGroup(TKey key, ObservableCollection collection)
: base(collection)
{
Key = key;
}
///
/// Initializes a new instance of the class.
///
/// The to wrap.
public ReadOnlyObservableGroup(ObservableGroup group)
: base(group)
{
Key = group.Key;
}
///
/// Initializes a new instance of the class.
///
/// The key of the group.
/// The collection of items to add in the group.
public ReadOnlyObservableGroup(TKey key, IEnumerable collection)
: base(new ObservableCollection(collection))
{
Key = key;
}
///
public TKey Key { get; }
///
object IReadOnlyObservableGroup.Key => Key;
}