Range.Net 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Range.Net --version 1.1.0
NuGet\Install-Package Range.Net -Version 1.1.0
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="Range.Net" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Range.Net --version 1.1.0
#r "nuget: Range.Net, 1.1.0"
#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.
// Install Range.Net as a Cake Addin
#addin nuget:?package=Range.Net&version=1.1.0

// Install Range.Net as a Cake Tool
#tool nuget:?package=Range.Net&version=1.1.0

Range.NET

Range allows comparable types to be used as a range.

Basic Usage

Create a new range

var range = new Range<int>(1,10);

Assert.Equal(1, range.Minimum);
Assert.Equal(10, range.Maximum);

Range contains value

var range = new Range<int>(1,10);

Assert.True(range.Contains(1));
Assert.True(range.Contains(3));
Assert.True(range.Contains(10));
Assert.False(range.Contains(0));
Assert.False(range.Contains(11));

Range contains another

var range1 = new Range<int>(1,10);
var range2 = new Range<int>(4,5);

Assert.True(range1.Contains(range2));
Assert.False(range2.Contains(range1));

Range intersects with another

var range = new Range<int>(1,10);

Assert.True(range.Intersects(new Range<int>(0,2)));
Assert.True(range.Intersects(new Range<int>(0,11)));
Assert.True(range.Intersects(new Range<int>(9,11)));
Assert.True(range.Intersects(new Range<int>(1,9)));
Assert.False(range.Intersects(new Range<int>(-1,0)));
Assert.False(range.Intersects(new Range<int>(11,12)));

Union a range with another

var range1 = new Range<int>(1,6);
var range2 = new Range<int>(3,10);

var union = range1.Union(range2);

Assert.Equal(1, union.Miniumum);
Assert.Equal(2, union.Maximum);

Advanced Usage

Inclusivity/Exclusivity

A range may specfy inclusivity/exclusivity of the minimum and maximum values using the Inclusivity property. InclusiveMinInclusiveMax the default used by Range.


var range1 = new Range<int>(1,10) { Inclusivity = ExclusiveMinExclusiveMax };
var range2 = new Range<int>(1,10) { Inclusivity = ExclusiveMinInclusiveMax };
var range3 = new Range<int>(1,10) { Inclusivity = InclusiveMinExclusiveMax };
var range4 = new Range<int>(1,10) { Inclusivity = InclusiveMinInclusiveMax };

Assert.False(range1.Contains(1));
Assert.False(range1.Contains(10));

Assert.True(range2.Contains(1))
Assert.False(range2.Contains(10))

Assert.True(range3.Contains(1))
Assert.False(range3.Contains(10))

Assert.True(range4.Contains(1))
Assert.True(range4.Contains(10))

IQueryable filtering

The library includes extensions to IQueryable which can be used with entity framework to filter a property by a range of the same type. This will automatically handle inclusivity.

var range = new Range<int>(3, 6);
var queryable = Enumerable
    .Range(1, 10)
    .Select(i => (intVal: i, strVal: i.ToString()))
    .AsQueryable();
var actual = queryable.FilterByRange(a => a.intVal, range);

Assert.Equal(
    new[] {
        (3, "3"),
        (4, "4"),
        (5, "5"),
        (6, "6")
    },
    actual
);
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 was computed.  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. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.1

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Range.Net:

Package Downloads
KSynthLib

Package Description

Sercalo.MM

Library to communicate with Sercalo Magnetic Mirror MM products

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 6,889 7/20/2021
2.5.3 394 7/19/2021
2.5.2 329 7/19/2021
2.5.1 1,173 5/6/2021
2.5.0 345 5/6/2021
2.4.0 81,061 2/24/2021
2.3.3 1,026 9/10/2020
2.3.2 440 9/8/2020
2.3.1 461 9/2/2020
2.2.1 465 9/2/2020
2.1.1 637 6/16/2020
2.1.0 477 6/16/2020
2.0.0 482 6/1/2020
1.3.2 457 5/12/2020
1.1.0 866 6/22/2019
1.0.0 668 6/21/2019