Bean/ObservableDictionary.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
namespace XStart2._0.Bean {
/// <summary>
/// 属性变更通知字典集合
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
public class ObservableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, INotifyCollectionChanged, INotifyPropertyChanged {
public ObservableDictionary() : base() { }
private int _index;
public event NotifyCollectionChangedEventHandler CollectionChanged;
public event PropertyChangedEventHandler PropertyChanged;
public new KeyCollection Keys => base.Keys;
public new ValueCollection Values => base.Values;
public new int Count => base.Count;
public new TValue this[TKey key] {
get => GetValue(key);
set => SetValue(key, value);
}
public TValue this[int index] {
get => GetIndexValue(index);
set => SetIndexValue(index, value);
}
public new void Add(TKey key, TValue value) {
base.Add(key, value);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, FindPair(key), _index));
OnPropertyChanged("Keys");
OnPropertyChanged("Values");
OnPropertyChanged("Count");
}
public new void Clear() {
base.Clear();
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
OnPropertyChanged("Keys");
OnPropertyChanged("Values");
OnPropertyChanged("Count");
}
public new bool Remove(TKey key) {
KeyValuePair<TKey, TValue> pair = FindPair(key);
if (base.Remove(key)) {
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, pair, _index));
OnPropertyChanged("Keys");
OnPropertyChanged("Values");
OnPropertyChanged("Count");
return true;
}
后面还有 76 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
