修正高并发时的空引用异常
大石头 authored at 2018-06-05 10:51:55
882.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
            {
                //return ContainsKey(item) && base[item];
                return TryGetValue(item, out var flag) && flag;
            }
            set
            {
                base[item] = value;
            }
        }
    }
}