using KGIS.Plugin.LayerProperty.Utils; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace KGIS.Plugin.LayerProperty.Model { public abstract class AbstractStorage { public class Collections : IEnumerable { private IList> mList; public int Count { get { return this.mList.Count; } } public T this[string instance] { get { if (instance == "") { return default(T); } foreach (ItemInfo current in this.mList) { if (current.InnerValue.Equals(instance)) { return current.DisplayValue; } } return default(T); } } public T this[int index] { get { if (index < 0 && index > this.mList.Count) { return default(T); } return this.mList[index].DisplayValue; } } internal Collections() { this.mList = new List>(); } internal void Add(ItemInfo item) { this.mList.Add(item); } internal bool Remove(ItemInfo item) { foreach (ItemInfo current in this.mList) { if (current.InnerValue == item.InnerValue) { this.mList.Remove(current); return true; } } return false; } internal bool Remove(string ItemKey) { foreach (ItemInfo current in this.mList) { if (current.InnerValue == ItemKey) { this.mList.Remove(current); return true; } } return false; } internal bool Exist(ItemInfo item) { foreach (ItemInfo current in this.mList) { if (current.InnerValue == item.InnerValue) { return true; } } return false; } IEnumerator IEnumerable.GetEnumerator() { foreach (ItemInfo current in this.mList) { yield return current.DisplayValue; } yield break; } internal void Clear() { this.mList.Clear(); } } private AbstractStorage.Collections collections; protected AbstractStorage.Collections Collection { get { return this.collections; } } protected bool Remove(ItemInfo item) { return this.collections.Remove(item); } protected bool Remove(string itemKey) { return this.collections.Remove(itemKey); } protected bool Add(ItemInfo item) { if (!this.Exist(item)) { this.collections.Add(item); return true; } return false; } protected void Clear() { this.collections.Clear(); } protected bool Exist(ItemInfo item) { return this.collections.Exist(item); } protected AbstractStorage() { this.collections = new AbstractStorage.Collections(); } } }