Range.Net
1.3.2
See the version list below for details.
dotnet add package Range.Net --version 1.3.2
NuGet\Install-Package Range.Net -Version 1.3.2
<PackageReference Include="Range.Net" Version="1.3.2" />
paket add Range.Net --version 1.3.2
#r "nuget: Range.Net, 1.3.2"
// Install Range.Net as a Cake Addin #addin nuget:?package=Range.Net&version=1.3.2 // Install Range.Net as a Cake Tool #tool nuget:?package=Range.Net&version=1.3.2
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.Minimum);
Assert.Equal(10, union.Maximum);
Greater/Less Than
var range = new Range<int>(4,6);
Assert.True(range.LessThan(7));
Assert.False(range.LessThan(5));
Assert.True(range.GreaterThan(3));
Assert.False(range.GreaterThan(4));
Compare To
var range1 = new Range<int>(4,6);
Assert.Equal(1, range1.CompareTo(1));
Assert.Equal(0, range1.CompareTo(4));
Assert.Equal(0, range1.CompareTo(5));
Assert.Equal(0, range1.CompareTo(6));
Assert.Equal(-1, range1.CompareTo(7));
Advanced Usage
Inclusivity/Exclusivity
A range may specify 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 = RangeInclusivity.ExclusiveMinExclusiveMax };
var range2 = new Range<int>(1,10) { Inclusivity = RangeInclusivity.ExclusiveMinInclusiveMax };
var range3 = new Range<int>(1,10) { Inclusivity = RangeInclusivity.InclusiveMinExclusiveMax };
var range4 = new Range<int>(1,10) { Inclusivity = RangeInclusivity.InclusiveMinInclusiveMax };
Assert.False(range1.Contains(1));
Assert.False(range1.Contains(10));
Assert.False(range2.Contains(1));
Assert.True(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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
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,965 | 7/20/2021 |
2.5.3 | 421 | 7/19/2021 |
2.5.2 | 355 | 7/19/2021 |
2.5.1 | 1,278 | 5/6/2021 |
2.5.0 | 375 | 5/6/2021 |
2.4.0 | 116,873 | 2/24/2021 |
2.3.3 | 1,051 | 9/10/2020 |
2.3.2 | 465 | 9/8/2020 |
2.3.1 | 493 | 9/2/2020 |
2.2.1 | 495 | 9/2/2020 |
2.1.1 | 667 | 6/16/2020 |
2.1.0 | 495 | 6/16/2020 |
2.0.0 | 504 | 6/1/2020 |
1.3.2 | 469 | 5/12/2020 |
1.1.0 | 890 | 6/22/2019 |
1.0.0 | 707 | 6/21/2019 |