diff --git a/Toolkit.Foundation/Cache.cs b/Toolkit.Foundation/Cache.cs index 5ad43f1..d067ed4 100644 --- a/Toolkit.Foundation/Cache.cs +++ b/Toolkit.Foundation/Cache.cs @@ -44,6 +44,17 @@ public class Cache(IComparer? comparer = default) : return false; } + public bool Contains(TValue key) + { + int index = items.BinarySearch(key, comparer); + if (index >= 0) + { + return true; + } + + return false; + } + public bool TryGetValue(TValue key, out TValue? item) { int index = items.BinarySearch(key, comparer); @@ -147,6 +158,17 @@ public class Cache(IComparer comparer) : return false; } + public bool Contains(TKey key) + { + int index = items.FindIndex(kvp => comparer.Compare(kvp.Key, key) == 0); + if (index >= 0) + { + items.RemoveAt(index); + return true; + } + return false; + } + private class KeyValuePairComparer(IComparer comparer) : IComparer> { diff --git a/Toolkit.Foundation/Edit.cs b/Toolkit.Foundation/Edit.cs deleted file mode 100644 index 9edf1f3..0000000 --- a/Toolkit.Foundation/Edit.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Toolkit.Foundation; - -public record Edit -{ - public static EditEventArgs As(TValue value) => - new(value); - - public static EditEventArgs As() where TValue : new() => - new(new TValue()); -} \ No newline at end of file diff --git a/Toolkit.Foundation/EditEventArgs.cs b/Toolkit.Foundation/EditEventArgs.cs deleted file mode 100644 index 2e3b649..0000000 --- a/Toolkit.Foundation/EditEventArgs.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace Toolkit.Foundation; - -public record EditEventArgs(TValue Value); \ No newline at end of file diff --git a/Toolkit.Foundation/ICache.cs b/Toolkit.Foundation/ICache.cs index 669a9a1..2220c74 100644 --- a/Toolkit.Foundation/ICache.cs +++ b/Toolkit.Foundation/ICache.cs @@ -7,11 +7,13 @@ public interface ICache : void Clear(); - bool TryGetValue(TValue key, out TValue? item); + bool Contains(TValue key); int IndexOf(TValue value); bool Remove(TValue value); + + bool TryGetValue(TValue key, out TValue? item); } public interface ICache : @@ -25,6 +27,8 @@ public interface ICache : void Clear(); + bool Contains(TKey key); + int IndexOf(TKey key); bool Remove(TKey key); diff --git a/Toolkit.Foundation/Update.cs b/Toolkit.Foundation/Update.cs new file mode 100644 index 0000000..5703a48 --- /dev/null +++ b/Toolkit.Foundation/Update.cs @@ -0,0 +1,10 @@ +namespace Toolkit.Foundation; + +public record Update +{ + public static UpdateEventArgs As(TValue value) => + new(value); + + public static UpdateEventArgs As() where TValue : new() => + new(new TValue()); +} \ No newline at end of file diff --git a/Toolkit.Foundation/UpdateEventArgs.cs b/Toolkit.Foundation/UpdateEventArgs.cs new file mode 100644 index 0000000..9757d1b --- /dev/null +++ b/Toolkit.Foundation/UpdateEventArgs.cs @@ -0,0 +1,3 @@ +namespace Toolkit.Foundation; + +public record UpdateEventArgs(TValue Value); \ No newline at end of file