改Dictionary为ConcurrentDictionary,解决多线程冲突
chenqilscy authored at 2015-12-18 20:33:36
970.00 B
X
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace XCode
{
    /// <summary>脏属性集合</summary>
    /// <remarks>实现IDictionary接口,为了让使用者能直接使用重载了的索引器</remarks>
    [Serializable]
    class DirtyCollection : ConcurrentDictionary<String, Boolean>, IDictionary<String, Boolean>
    {
        /// <summary>获取或设置与指定的属性是否有脏数据。</summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public new Boolean this[String item]
        {
            get
            {
                //if (ContainsKey(item) && base[item])
                //    return true;
                //else
                //    return false;
                return ContainsKey(item) && base[item];
            }
            set
            {
                base[item] = value;
            }
        }
    }
}