using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Text; namespace Ant.ORM { /// /// 缓存值类 /// public class FieldValueCollection { private Dictionary fields = new Dictionary(); private static object lockHelper = new object(); private static volatile FieldValueCollection instance = null; public FieldValueCollection() { } public static FieldValueCollection Instance { get { if (instance == null) { lock (lockHelper) { if (instance == null) { instance = new FieldValueCollection(); } } } return instance; } } #region IDictionary 成员 /// /// 向集合中添加元素 /// /// /// public void Add(string key, object value) { if (!Contains(key)) fields.Add(key, value); else fields[key] = value; } /// /// 移除集合中所有元素 /// public void Clear() { fields.Clear(); } /// /// 判断集合中是否有该元素 /// /// /// 有返true;没有返回false public bool Contains(string key) { return fields.ContainsKey(key); } public IDictionaryEnumerator GetEnumerator() { return fields.GetEnumerator(); } public bool IsFixedSize { get { return false; } } public bool IsReadOnly { get { return false; } } public ICollection Keys { get { return fields.Keys; } } /// /// 移除集合中元素 /// /// public void Remove(string key) { fields.Remove(key); } /// /// 获取集合中值 /// public ICollection Values { get { return fields.Values; } } /// /// 获取key的值 /// /// /// public object this[string key] { get { if (Contains(key)) return fields[key]; else return null; } set { if (Contains(key)) fields[key] = value; else fields.Add(key, value); } } #endregion #region ICollection 成员 /// /// 将Dictionary复到Array中 /// /// /// public void CopyTo(Array array, int index) { foreach (string key in fields.Keys) { FieldValue fv = new FieldValue(key, fields[key]); array.SetValue(fv, index); index++; } } /// /// 集合中所有元素的记录 /// public int Count { get { return fields.Count; } } public bool IsSynchronized { get { return false; ; } } public object SyncRoot { get { return this; } } #endregion } }