Skip to content

Commit

Permalink
[DO NOT MERGE]: IKeyValueCollection as IReadOnlyList (#874)
Browse files Browse the repository at this point in the history
* ReSharper disable once CheckNamespace

* impliment IReadOnlyList

* Revert " ReSharper disable once CheckNamespace"

This reverts commit 5771555.

* fix test

* review feedback

---------

Co-authored-by: Glenn <5834289+glennawatson@users.noreply.github.com>
Co-authored-by: Darrin W. Cullop <Darrin.Cullop@microsoft.com>
Co-authored-by: Roland Pheasant <roland_pheasant@hotmail.com>
  • Loading branch information
4 people authored Jun 3, 2024
1 parent 275cc2c commit cec559b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,9 @@ namespace DynamicData
{
void Edit(System.Action<DynamicData.ICacheUpdater<TObject, TKey>> updateAction);
}
public interface IKeyValueCollection<TObject, TKey> : System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TObject>>, System.Collections.IEnumerable
public interface IKeyValueCollection<TObject, TKey> : System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TObject>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TObject>>, System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<TKey, TObject>>, System.Collections.IEnumerable
{
System.Collections.Generic.IComparer<System.Collections.Generic.KeyValuePair<TKey, TObject>> Comparer { get; }
int Count { get; }
System.Collections.Generic.KeyValuePair<TKey, TObject> this[int index] { get; }
DynamicData.SortOptimisations Optimisations { get; }
DynamicData.SortReason SortReason { get; }
}
Expand Down
16 changes: 8 additions & 8 deletions src/DynamicData.Tests/Cache/SortFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
21 changes: 1 addition & 20 deletions src/DynamicData/Cache/IKeyValueCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DynamicData;
/// </summary>
/// <typeparam name="TObject">The type of the object.</typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
public interface IKeyValueCollection<TObject, TKey> : IEnumerable<KeyValuePair<TKey, TObject>>
public interface IKeyValueCollection<TObject, TKey> : IReadOnlyList<KeyValuePair<TKey, TObject>>
{
/// <summary>
/// Gets the comparer used to perform the sort.
Expand All @@ -20,14 +20,6 @@ public interface IKeyValueCollection<TObject, TKey> : IEnumerable<KeyValuePair<T
/// </value>
IComparer<KeyValuePair<TKey, TObject>> Comparer { get; }

/// <summary>
/// Gets the count of items.
/// </summary>
/// <value>
/// The count.
/// </value>
int Count { get; }

/// <summary>
/// Gets the optimisations used to produce the sort.
/// </summary>
Expand All @@ -43,15 +35,4 @@ public interface IKeyValueCollection<TObject, TKey> : IEnumerable<KeyValuePair<T
/// The sort reason.
/// </value>
SortReason SortReason { get; }

/// <summary>
/// Gets the element at the specified index in the read-only list.
/// </summary>
///
/// <returns>
/// The element at the specified index in the read-only list.
/// </returns>
/// <param name="index">The zero-based index of the element to get. </param>
/// <returns>The key value pair.</returns>
KeyValuePair<TKey, TObject> this[int index] { get; }
}

0 comments on commit cec559b

Please sign in to comment.