using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; namespace MCTGLib { public class RecipeCollection : IList, IEquatable { #region Attributes private List _recipes; #endregion #region Properties public string Description { get; set; } #region IList Prperties public int Count => _recipes.Count; public bool IsReadOnly => false; public Recipe this[int index] { get => _recipes[index]; set => _recipes[index] = value; } #endregion #endregion #region Constructors public RecipeCollection(string description = "No Description.") { _recipes = new List(); Description = description; } public RecipeCollection(params Recipe[] recipes) { _recipes = new List(recipes); Description = "No Description."; } #endregion #region Methods #region IList Methods public int IndexOf(Recipe item) { return _recipes.IndexOf(item); } public void Insert(int index, Recipe item) { _recipes.Insert(index, item); } public void RemoveAt(int index) { _recipes.RemoveAt(index); } public void Add(Recipe item) { _recipes.Add(item); } public void Clear() { _recipes.Clear(); } public bool Contains(Recipe item) { return _recipes.Contains(item); } public void CopyTo(Recipe[] array, int arrayIndex) { _recipes.CopyTo(array, arrayIndex); } public bool Remove(Recipe item) { return _recipes.Remove(item); } public IEnumerator GetEnumerator() { return _recipes.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return _recipes.GetEnumerator(); } #endregion #region IEquatable Mathods public bool Equals(RecipeCollection? other) { if (other == null) return false; if (other == this) return true; return Description.Equals(other.Description) && _recipes.Equals(other._recipes); } #endregion public override int GetHashCode() { return Description.GetHashCode() + _recipes.GetHashCode(); } #endregion } }