1 Star 0 Fork 0

ewin66/RegExplore

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
EventDictionary.cs 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
Muhammad Hasan Khan 提交于 2017-04-19 07:24 . Initial commit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CrackSoft.Collections
{
class ItemEventArgs<TKey, TValue>: EventArgs
{
public KeyValuePair<TKey, TValue> Item
{
get;
set;
}
public ItemEventArgs(TKey key, TValue value)
{
Item = new KeyValuePair<TKey, TValue>(key, value);
}
}
class EventDictionary<TKey, TValue> : Dictionary<TKey, TValue>
{
public event EventHandler<ItemEventArgs<TKey, TValue>> ItemAdded;
public event EventHandler<ItemEventArgs<TKey, TValue>> ItemRemoved;
public new void Add(TKey key, TValue value)
{
base.Add(key, value);
if (ItemAdded != null)
ItemAdded(this, new ItemEventArgs<TKey, TValue>(key, value));
}
public new bool Remove(TKey key)
{
TValue value = base[key];
bool result = base.Remove(key);
if (result && ItemRemoved != null)
ItemRemoved(this, new ItemEventArgs<TKey, TValue>(key, value));
return result;
}
public new TValue this[TKey key]
{
get
{
return base[key];
}
set
{
bool exists = base.ContainsKey(key);
base[key] = value;
if (!exists && ItemAdded != null)
ItemAdded(this, new ItemEventArgs<TKey, TValue>(key, value));
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/EWIN66/RegExplore.git
[email protected]:EWIN66/RegExplore.git
EWIN66
RegExplore
RegExplore
master

搜索帮助