From cec559b151ca4b65586b313b8185141834d9752f Mon Sep 17 00:00:00 2001 From: kronic Date: Mon, 3 Jun 2024 13:52:36 +0300 Subject: [PATCH] [DO NOT MERGE]: IKeyValueCollection as IReadOnlyList (#874) * ReSharper disable once CheckNamespace * impliment IReadOnlyList * Revert " ReSharper disable once CheckNamespace" This reverts commit 57715554bf1d1a84b7c5b7dfd8d081dcea9421e6. * fix test * review feedback --------- Co-authored-by: Glenn <5834289+glennawatson@users.noreply.github.com> Co-authored-by: Darrin W. Cullop Co-authored-by: Roland Pheasant --- ...ts.DynamicDataTests.DotNet8_0.verified.txt | 4 +--- src/DynamicData.Tests/Cache/SortFixture.cs | 16 +++++++------- src/DynamicData/Cache/IKeyValueCollection.cs | 21 +------------------ 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt index bbf24584b..305ec585b 100644 --- a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt +++ b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt @@ -861,11 +861,9 @@ namespace DynamicData { void Edit(System.Action> updateAction); } - public interface IKeyValueCollection : System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable + public interface IKeyValueCollection : System.Collections.Generic.IEnumerable>, System.Collections.Generic.IReadOnlyCollection>, System.Collections.Generic.IReadOnlyList>, System.Collections.IEnumerable { System.Collections.Generic.IComparer> Comparer { get; } - int Count { get; } - System.Collections.Generic.KeyValuePair this[int index] { get; } DynamicData.SortOptimisations Optimisations { get; } DynamicData.SortReason SortReason { get; } } diff --git a/src/DynamicData.Tests/Cache/SortFixture.cs b/src/DynamicData.Tests/Cache/SortFixture.cs index e80b98ef5..0f228b173 100644 --- a/src/DynamicData.Tests/Cache/SortFixture.cs +++ b/src/DynamicData.Tests/Cache/SortFixture.cs @@ -302,7 +302,7 @@ public void RemoveFirst() _source.AddOrUpdate(people); //create age 0 to ensure it is inserted first - var remove = _results.Messages[0].SortedItems.First(); + var remove = _results.Messages[0].SortedItems[0]; _source.Remove(remove.Key); @@ -323,7 +323,7 @@ public void RemoveFromEnd() _source.AddOrUpdate(people); //create age 0 to ensure it is inserted first - var remove = _results.Messages[0].SortedItems.Last(); + var remove = _results.Messages[0].SortedItems[^1]; _source.Remove(remove.Key); @@ -421,7 +421,7 @@ public void UpdateFirst() var people = _generator.Take(100).ToArray(); _source.AddOrUpdate(people); - var toupdate = _results.Messages[0].SortedItems.First().Value; + var toupdate = _results.Messages[0].SortedItems[0].Value; var update = new Person(toupdate.Name, toupdate.Age + 5); _source.AddOrUpdate(update); @@ -444,7 +444,7 @@ public void UpdateLast() var people = _generator.Take(100).ToArray(); _source.AddOrUpdate(people); - var toupdate = _results.Messages[0].SortedItems.Last().Value; + var toupdate = _results.Messages[0].SortedItems[^1].Value; var update = new Person(toupdate.Name, toupdate.Age + 5); _source.AddOrUpdate(update); @@ -828,7 +828,7 @@ public void RemoveFirst() _source.AddOrUpdate(people); //create age 0 to ensure it is inserted first - var remove = _results.Messages[0].SortedItems.First(); + var remove = _results.Messages[0].SortedItems[0]; _source.Remove(remove.Key); @@ -849,7 +849,7 @@ public void RemoveFromEnd() _source.AddOrUpdate(people); //create age 0 to ensure it is inserted first - var remove = _results.Messages[0].SortedItems.Last(); + var remove = _results.Messages[0].SortedItems[^1]; _source.Remove(remove.Key); @@ -947,7 +947,7 @@ public void UpdateFirst() var people = _generator.Take(100).ToArray(); _source.AddOrUpdate(people); - var toupdate = _results.Messages[0].SortedItems.First().Value; + var toupdate = _results.Messages[0].SortedItems[0].Value; var update = new Person(toupdate.Name, toupdate.Age + 5); _source.AddOrUpdate(update); @@ -970,7 +970,7 @@ public void UpdateLast() var people = _generator.Take(100).ToArray(); _source.AddOrUpdate(people); - var toupdate = _results.Messages[0].SortedItems.Last().Value; + var toupdate = _results.Messages[0].SortedItems[^1].Value; var update = new Person(toupdate.Name, toupdate.Age + 5); _source.AddOrUpdate(update); diff --git a/src/DynamicData/Cache/IKeyValueCollection.cs b/src/DynamicData/Cache/IKeyValueCollection.cs index e28bd7a36..01a55bb5e 100644 --- a/src/DynamicData/Cache/IKeyValueCollection.cs +++ b/src/DynamicData/Cache/IKeyValueCollection.cs @@ -10,7 +10,7 @@ namespace DynamicData; /// /// The type of the object. /// The type of the key. -public interface IKeyValueCollection : IEnumerable> +public interface IKeyValueCollection : IReadOnlyList> { /// /// Gets the comparer used to perform the sort. @@ -20,14 +20,6 @@ public interface IKeyValueCollection : IEnumerable IComparer> Comparer { get; } - /// - /// Gets the count of items. - /// - /// - /// The count. - /// - int Count { get; } - /// /// Gets the optimisations used to produce the sort. /// @@ -43,15 +35,4 @@ public interface IKeyValueCollection : IEnumerable SortReason SortReason { get; } - - /// - /// Gets the element at the specified index in the read-only list. - /// - /// - /// - /// The element at the specified index in the read-only list. - /// - /// The zero-based index of the element to get. - /// The key value pair. - KeyValuePair this[int index] { get; } }