123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Collections.Specialized;
- using System.Text;
- namespace Ant.ORM
- {
- /// <summary>
- /// 缓存值类
- /// </summary>
- public class FieldValueCollection
- {
- private Dictionary<string, object> fields = new Dictionary<string, object>();
- 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 成员
- /// <summary>
- /// 向集合中添加元素
- /// </summary>
- /// <param name="key"></param>
- /// <param name="value"></param>
- public void Add(string key, object value)
- {
- if (!Contains(key))
- fields.Add(key, value);
- else
- fields[key] = value;
- }
- /// <summary>
- /// 移除集合中所有元素
- /// </summary>
- public void Clear()
- {
- fields.Clear();
- }
- /// <summary>
- /// 判断集合中是否有该元素
- /// </summary>
- /// <param name="key"></param>
- /// <returns>有返true;没有返回false</returns>
- 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; }
- }
- /// <summary>
- /// 移除集合中元素
- /// </summary>
- /// <param name="key"></param>
- public void Remove(string key)
- {
- fields.Remove(key);
- }
- /// <summary>
- /// 获取集合中值
- /// </summary>
- public ICollection Values
- {
- get { return fields.Values; }
- }
- /// <summary>
- /// 获取key的值
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- 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 成员
- /// <summary>
- /// 将Dictionary复到Array中
- /// </summary>
- /// <param name="array"></param>
- /// <param name="index"></param>
- 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++;
- }
- }
- /// <summary>
- /// 集合中所有元素的记录
- /// </summary>
- public int Count
- {
- get { return fields.Count; }
- }
- public bool IsSynchronized
- {
- get { return false; ; }
- }
- public object SyncRoot
- {
- get { return this; }
- }
- #endregion
- }
- }
|