diff --git a/src/ObservableCollections/ObservableDictionary.cs b/src/ObservableCollections/ObservableDictionary.cs index 897ac7e..e1c3d27 100644 --- a/src/ObservableCollections/ObservableDictionary.cs +++ b/src/ObservableCollections/ObservableDictionary.cs @@ -13,17 +13,17 @@ namespace ObservableCollections readonly Dictionary dictionary; public object SyncRoot { get; } = new object(); - public ObservableDictionary() + public ObservableDictionary(IEqualityComparer? comparer = null) { - this.dictionary = new Dictionary(); + this.dictionary = new Dictionary(comparer: comparer); } - public ObservableDictionary(IEnumerable> collection) + public ObservableDictionary(IEnumerable> collection, IEqualityComparer? comparer = null) { -#if NET6_0_OR_GREATER - this.dictionary = new Dictionary(collection); +#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER + this.dictionary = new Dictionary(collection: collection, comparer: comparer); #else - this.dictionary = new Dictionary(); + this.dictionary = new Dictionary(comparer: comparer); foreach (var item in collection) { dictionary.Add(item.Key, item.Value); @@ -224,5 +224,16 @@ namespace ObservableCollections { return GetEnumerator(); } + + public IEqualityComparer Comparer + { + get + { + lock (SyncRoot) + { + return dictionary.Comparer; + } + } + } } } diff --git a/src/ObservableCollections/ObservableHashSet.cs b/src/ObservableCollections/ObservableHashSet.cs index 8e2e1d4..08076cc 100644 --- a/src/ObservableCollections/ObservableHashSet.cs +++ b/src/ObservableCollections/ObservableHashSet.cs @@ -14,23 +14,23 @@ namespace ObservableCollections readonly HashSet set; public object SyncRoot { get; } = new object(); - public ObservableHashSet() + public ObservableHashSet(IEqualityComparer? comparer = null) { - this.set = new HashSet(); + this.set = new HashSet(comparer: comparer); } #if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER - public ObservableHashSet(int capacity) + public ObservableHashSet(int capacity, IEqualityComparer? comparer = null) { - this.set = new HashSet(capacity); + this.set = new HashSet(capacity: capacity, comparer: comparer); } #endif - public ObservableHashSet(IEnumerable collection) + public ObservableHashSet(IEnumerable collection, IEqualityComparer? comparer = null) { - this.set = new HashSet(collection); + this.set = new HashSet(collection: collection, comparer: comparer); } public event NotifyCollectionChangedEventHandler? CollectionChanged; @@ -264,5 +264,16 @@ namespace ObservableCollections { return GetEnumerator(); } + + public IEqualityComparer Comparer + { + get + { + lock (SyncRoot) + { + return set.Comparer; + } + } + } } }