namespace HaWeb.Models; using HaWeb.XMLParser; public class ItemsCollection { public string Name { get; private set; } public IDictionary Items { get; private set; } public IXMLCollection Collection { get; private set; } public IDictionary>? Groupings { get; private set; } public IDictionary>? Sortings { get; private set; } public ItemsCollection( string name, IXMLCollection collection ) { this.Name = name; this.Collection = collection; this.Items = new Dictionary(); } public void GenerateGroupings( Func, Dictionary>?>? groupingsFunc = null ) { if (groupingsFunc != null) { this.Groupings = groupingsFunc(this.Items.Values.ToList()); return; } if (Collection.GroupingsGeneration != null && this.Items.Any()) this.Groupings = Collection.GroupingsGeneration(this.Items.Values.ToList()); } public void GenerateSortings( Func, Dictionary>?>? sortingsFunc = null ) { if (sortingsFunc != null) { this.Sortings = sortingsFunc(this.Items.Values.ToList()); return; } if (Collection.SortingsGeneration != null && this.Items.Any()) this.Sortings = Collection.SortingsGeneration(this.Items.Values.ToList()); } public CollectedItem? this[string v] { get { if (Items != null && Items.ContainsKey(v)) return Items[v]; return null; } } }