Range.Net
1.0.0
See the version list below for details.
dotnet add package Range.Net --version 1.0.0
NuGet\Install-Package Range.Net -Version 1.0.0
<PackageReference Include="Range.Net" Version="1.0.0" />
paket add Range.Net --version 1.0.0
#r "nuget: Range.Net, 1.0.0"
// Install Range.Net as a Cake Addin #addin nuget:?package=Range.Net&version=1.0.0 // Install Range.Net as a Cake Tool #tool nuget:?package=Range.Net&version=1.0.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 | 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 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. |
-
.NETCoreApp 2.1
- Range.Net.Abstractions (>= 1.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Range.Net:
Package | Downloads |
---|---|
KSynthLib
Package Description |
|
Sercalo.MM
Library to communicate with Sercalo Magnetic Mirror MM products |
|
Sercalo.SC
Library to communicate with Sercalo SC switch products |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.0.0 | 11,530 | 7/20/2021 |
2.5.3 | 419 | 7/19/2021 |
2.5.2 | 353 | 7/19/2021 |
2.5.1 | 1,276 | 5/6/2021 |
2.5.0 | 373 | 5/6/2021 |
2.4.0 | 115,304 | 2/24/2021 |
2.3.3 | 1,049 | 9/10/2020 |
2.3.2 | 463 | 9/8/2020 |
2.3.1 | 491 | 9/2/2020 |
2.2.1 | 493 | 9/2/2020 |
2.1.1 | 665 | 6/16/2020 |
2.1.0 | 491 | 6/16/2020 |
2.0.0 | 502 | 6/1/2020 |
1.3.2 | 467 | 5/12/2020 |
1.1.0 | 888 | 6/22/2019 |
1.0.0 | 703 | 6/21/2019 |