diff --git a/Chickensoft.Collections.Tests/src/extensions/HashSetExTest.cs b/Chickensoft.Collections.Tests/src/extensions/HashSetExTest.cs new file mode 100644 index 0000000..d4deb16 --- /dev/null +++ b/Chickensoft.Collections.Tests/src/extensions/HashSetExTest.cs @@ -0,0 +1,25 @@ +namespace Chickensoft.Collections.Tests; + +using System.Collections.Generic; +using Shouldly; +using Xunit; + +public class HashSetExTest { + [Fact] + public void WithIncludesItem() { + var set = new HashSet { 1, 2, 3 }; + var result = set.With(4); + + result.ShouldContain(4); + result.Count.ShouldBe(4); + } + + [Fact] + public void WithoutExcludesItem() { + var set = new HashSet { 1, 2, 3 }; + var result = set.Without(2); + + result.ShouldNotContain(2); + result.Count.ShouldBe(2); + } +} diff --git a/Chickensoft.Collections/src/extensions/HashSetEx.cs b/Chickensoft.Collections/src/extensions/HashSetEx.cs new file mode 100644 index 0000000..b567629 --- /dev/null +++ b/Chickensoft.Collections/src/extensions/HashSetEx.cs @@ -0,0 +1,33 @@ +namespace Chickensoft.Collections; + +using System.Collections.Generic; + +/// +/// extensions. +/// +public static class HashSetEx { + /// + /// Creates a copy of the hash set with the specified item included. + /// + /// Type of the item. + /// Hash set. + /// Item to include. + /// A new hash set. + public static HashSet With(this HashSet set, T item) { + var copy = new HashSet(set) { item }; + return copy; + } + + /// + /// Creates a copy of the hash set with the specified item excluded. + /// + /// Type of the item. + /// Hash set. + /// Item to exclude. + /// A new hash set. + public static HashSet Without(this HashSet set, T item) { + var copy = new HashSet(set); + copy.Remove(item); + return copy; + } +} diff --git a/global.json b/global.json index 4c868ba..510f4d9 100644 --- a/global.json +++ b/global.json @@ -4,6 +4,6 @@ }, "sdk": { "rollForward": "major", - "version": "9.0.100-rc.1.24452.12" + "version": "8.0.401" } } diff --git a/renovate.json b/renovate.json index 8ea4779..bf94541 100644 --- a/renovate.json +++ b/renovate.json @@ -13,7 +13,8 @@ ], "groupName": "all dependencies", "groupSlug": "all-deps", - "automerge": true + "automerge": true, + "allowedVersions": "!/preview/" }, { "matchPackagePrefixes": [