You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SAE-2.01/MCTG/MCTGLib/RecipeCollection.cs

108 lines
2.7 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace MCTGLib
{
public class RecipeCollection : IList<Recipe>, IEquatable<RecipeCollection>
{
#region Attributes
private List<Recipe> _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<Recipe>();
Description = description;
}
public RecipeCollection(params Recipe[] recipes)
{
_recipes = new List<Recipe>(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<Recipe> 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
}
}