Wolfgang.Extensions.IComparable
1.1.2
Prefix Reserved
dotnet add package Wolfgang.Extensions.IComparable --version 1.1.2
NuGet\Install-Package Wolfgang.Extensions.IComparable -Version 1.1.2
<PackageReference Include="Wolfgang.Extensions.IComparable" Version="1.1.2" />
<PackageVersion Include="Wolfgang.Extensions.IComparable" Version="1.1.2" />
<PackageReference Include="Wolfgang.Extensions.IComparable" />
paket add Wolfgang.Extensions.IComparable --version 1.1.2
#r "nuget: Wolfgang.Extensions.IComparable, 1.1.2"
#:package Wolfgang.Extensions.IComparable@1.1.2
#addin nuget:?package=Wolfgang.Extensions.IComparable&version=1.1.2
#tool nuget:?package=Wolfgang.Extensions.IComparable&version=1.1.2
Wolfgang.Extensions.IComparable
Extension methods for IComparable<T> that make ordering and range checks read the way you'd say them — value.IsBetween(low, high) instead of value.CompareTo(low) > 0 && value.CompareTo(high) < 0.
📦 Installation
dotnet add package Wolfgang.Extensions.IComparable
NuGet Package: Wolfgang.Extensions.IComparable
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
📚 Documentation
- GitHub Repository: https://github.com/Chris-Wolfgang/IComparable-Extensions
- API Documentation: https://Chris-Wolfgang.github.io/IComparable-Extensions/
- CHANGELOG: CHANGELOG.md
- Contributing Guide: CONTRIBUTING.md
✨ Methods
All methods are generic extension methods on T where T : IComparable<T>. Both throw ArgumentNullException when value is null.
| Method | Bound semantics | Returns true when |
|---|---|---|
value.IsBetween(lowerBound, upperBound) |
Exclusive on both ends | lowerBound < value < upperBound |
value.IsInRange(lowerBound, upperBound) |
Inclusive on both ends | lowerBound ≤ value ≤ upperBound |
The distinction matters when value exactly equals one of the bounds: IsBetween returns false, IsInRange returns true. Pick the one whose contract you want.
🚀 Usage
IsBetween — strict bounds
using Wolfgang.Extensions.IComparable;
int score = 75;
bool inOpenRange = score.IsBetween(70, 80); // true — 70 < 75 < 80
bool atLower = 70.IsBetween(70, 80); // false — 70 is NOT > 70
bool atUpper = 80.IsBetween(70, 80); // false — 80 is NOT < 80
IsInRange — inclusive bounds
using Wolfgang.Extensions.IComparable;
DateTime today = DateTime.UtcNow.Date;
DateTime quarterStart = new DateTime(2026, 4, 1);
DateTime quarterEnd = new DateTime(2026, 6, 30);
bool inQ2 = today.IsInRange(quarterStart, quarterEnd); // true on any Q2 date,
// including the boundary days
Works with any IComparable<T>
using Wolfgang.Extensions.IComparable;
// string
"banana".IsInRange("apple", "cherry"); // true — lexicographic ordering
// custom type — just implement IComparable<T>
public record Money(decimal Amount, string Currency) : IComparable<Money>
{
public int CompareTo(Money? other) =>
// Per the IComparable<T> contract, any non-null value is
// greater than null. Returning Amount.CompareTo(other?.Amount ?? 0m)
// would be wrong for negative Amount — a negative Money would
// compare as "less than" null instead of greater.
other is null ? 1 : Amount.CompareTo(other.Amount);
}
var price = new Money(19.99m, "USD");
price.IsBetween(new Money(10m, "USD"), new Money(50m, "USD")); // true
Null safety
string? maybeNull = null;
// The `!` keeps the example warning-free under <Nullable>enable</Nullable>;
// IsBetween's T is non-null, so without it the compiler complains. The
// runtime behaviour we're demonstrating is still the same:
maybeNull!.IsBetween("a", "z"); // throws ArgumentNullException("value")
🎯 Supported Frameworks
This library targets:
- .NET Framework: 4.6.2
- .NET Standard: 2.0
- .NET: 8.0, 10.0
See the NuGet package page for the authoritative per-TFM compatibility matrix.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.