年度变更建库软件5.0版本
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.

147 lines
4.2 KiB

4 months ago
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<T>
{
public class Collections : IEnumerable
{
private IList<ItemInfo<string, T>> mList;
public int Count
{
get
{
return this.mList.Count;
}
}
public T this[string instance]
{
get
{
if (instance == "")
{
return default(T);
}
foreach (ItemInfo<string, T> 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<ItemInfo<string, T>>();
}
internal void Add(ItemInfo<string, T> item)
{
this.mList.Add(item);
}
internal bool Remove(ItemInfo<string, T> item)
{
foreach (ItemInfo<string, T> current in this.mList)
{
if (current.InnerValue == item.InnerValue)
{
this.mList.Remove(current);
return true;
}
}
return false;
}
internal bool Remove(string ItemKey)
{
foreach (ItemInfo<string, T> current in this.mList)
{
if (current.InnerValue == ItemKey)
{
this.mList.Remove(current);
return true;
}
}
return false;
}
internal bool Exist(ItemInfo<string, T> item)
{
foreach (ItemInfo<string, T> current in this.mList)
{
if (current.InnerValue == item.InnerValue)
{
return true;
}
}
return false;
}
IEnumerator IEnumerable.GetEnumerator()
{
foreach (ItemInfo<string, T> current in this.mList)
{
yield return current.DisplayValue;
}
yield break;
}
internal void Clear()
{
this.mList.Clear();
}
}
private AbstractStorage<T>.Collections collections;
protected AbstractStorage<T>.Collections Collection
{
get
{
return this.collections;
}
}
protected bool Remove(ItemInfo<string, T> item)
{
return this.collections.Remove(item);
}
protected bool Remove(string itemKey)
{
return this.collections.Remove(itemKey);
}
protected bool Add(ItemInfo<string, T> item)
{
if (!this.Exist(item))
{
this.collections.Add(item);
return true;
}
return false;
}
protected void Clear()
{
this.collections.Clear();
}
protected bool Exist(ItemInfo<string, T> item)
{
return this.collections.Exist(item);
}
protected AbstractStorage()
{
this.collections = new AbstractStorage<T>.Collections();
}
}
}