// Copyright (c) Arlo Godfrey. All Rights Reserved. // Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms. // See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information. using System; using StrixMusic.Sdk.AppModels; using StrixMusic.Sdk.BaseModels; using StrixMusic.Sdk.CoreModels; namespace StrixMusic.Sdk.Extensions { public static partial class Cores { /// /// Gets the total items count from an by casting it to the specified collection type. /// /// The collection type to check the item count. /// The number of items for the given collection. public static int GetItemsCount(this ICoreMember source) where TCollection : ICollectionBase { if (source == null) throw new ArgumentNullException(nameof(source)); if (typeof(TCollection) == typeof(IPlayableCollectionGroup)) return ((IPlayableCollectionGroupBase)source).TotalChildrenCount; if (typeof(TCollection) == typeof(IAlbumCollection)) return ((IAlbumCollectionBase)source).TotalAlbumItemsCount; if (typeof(TCollection) == typeof(IArtistCollection)) return ((IArtistCollectionBase)source).TotalArtistItemsCount; if (typeof(TCollection) == typeof(IPlaylistCollection)) return ((IPlaylistCollectionBase)source).TotalPlaylistItemsCount; if (typeof(TCollection) == typeof(ITrackCollection)) return ((ITrackCollectionBase)source).TotalTrackCount; if (typeof(TCollection) == typeof(IImageCollection)) return ((IImageCollectionBase)source).TotalImageCount; if (typeof(TCollection) == typeof(IGenreCollection)) return ((IGenreCollectionBase)source).TotalGenreCount; throw new ArgumentOutOfRangeException(nameof(source)); } } }