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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Wolfgang.Extensions.IComparable" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Wolfgang.Extensions.IComparable" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Wolfgang.Extensions.IComparable" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Wolfgang.Extensions.IComparable --version 1.1.2
                    
#r "nuget: Wolfgang.Extensions.IComparable, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Wolfgang.Extensions.IComparable@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Wolfgang.Extensions.IComparable&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Wolfgang.Extensions.IComparable&version=1.1.2
                    
Install as a Cake Tool

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.

NuGet NuGet downloads PR build Release License: MIT .NET GitHub


📦 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


✨ 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last Updated
1.1.2 986 8/21/2026
1.1.1 230 6/3/2026
1.1.0 121 4/28/2026
1.0.0 132 1/20/2026
0.1.0-rc1 125 1/18/2026