Add PropertyChanged detection for Dictionary type settings
This commit is contained in:
parent
1f7000c2c9
commit
5c73beff4b
11 changed files with 211 additions and 179 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Dinah.Core;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
|
@ -151,5 +152,29 @@ namespace LibationFileManager
|
|||
_observers.Remove(_observer);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Use this type in the getter for any Dictionary<TKey, TValue> settings,
|
||||
* and be sure to clone it before returning. This allows Configuration to
|
||||
* accurately detect if an of the Dictionary's elements have changed.
|
||||
*/
|
||||
private class EquatableDictionary<TKey, TValue> : Dictionary<TKey, TValue>
|
||||
{
|
||||
public EquatableDictionary(IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs) : base(keyValuePairs) { }
|
||||
public EquatableDictionary<TKey, TValue> Clone() => new(this);
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Dictionary<TKey, TValue> dic && Count == dic.Count)
|
||||
{
|
||||
foreach (var pair in this)
|
||||
if (!dic.TryGetValue(pair.Key, out var value) || !pair.Value.Equals(value))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue