// 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.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
namespace CommunityToolkit.Common.Collections;
///
/// An observable list of observable groups.
///
/// The type of the group key.
/// The type of the items in the collection.
public sealed class ObservableGroupedCollection : ObservableCollection>
where TKey : notnull
{
///
/// Initializes a new instance of the class.
///
public ObservableGroupedCollection()
{
}
///
/// Initializes a new instance of the class.
///
/// The initial data to add in the grouped collection.
public ObservableGroupedCollection(IEnumerable> collection)
: base(collection.Select(static c => new ObservableGroup(c)))
{
}
///
/// Tries to get the underlying instance, if present.
///
/// The resulting , if one was in use.
/// Whether or not a instance has been found.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool TryGetList([NotNullWhen(true)] out List>? list)
{
list = Items as List>;
return list is not null;
}
}