Skip to content

Commit

Permalink
Initial code commit, forked from: https://github.com/Konard/LinksPlat…
Browse files Browse the repository at this point in the history
  • Loading branch information
Konard committed Jul 14, 2019
1 parent 3540d47 commit 505d917
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Platform.Ranges.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>LinksPlatform's Platform.Ranges Class Library</Description>
<Copyright>Konstantin Diachenko</Copyright>
<AssemblyTitle>Platform.Ranges</AssemblyTitle>
<VersionPrefix>0.0.1</VersionPrefix>
<Authors>Konstantin Diachenko</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Platform.Ranges</AssemblyName>
<PackageId>Platform.Ranges</PackageId>
<PackageTags>LinksPlatform;Ranges;Range</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/linksplatform/Documentation/d65e8dd6e1b647405bc3d33687172e79b70e3435/doc/Avatar-rainbow.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/linksplatform/Ranges</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/linksplatform/Ranges/blob/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/linksplatform/Ranges</RepositoryUrl>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions Platform.Ranges.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29020.237
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Platform.Ranges", "Platform.Ranges.csproj", "{37333E88-7378-427D-AFA6-3159F5F9628E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{37333E88-7378-427D-AFA6-3159F5F9628E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37333E88-7378-427D-AFA6-3159F5F9628E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37333E88-7378-427D-AFA6-3159F5F9628E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37333E88-7378-427D-AFA6-3159F5F9628E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4988D786-1DD3-408A-8E42-10D0F3F65B40}
EndGlobalSection
EndGlobal
77 changes: 77 additions & 0 deletions Range.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Collections.Generic;

namespace Platform.Ranges
{
/// <summary>
/// Represents a range between minumum and maximum values.
/// Представляет диапазон между минимальным и максимальным значениями.
/// </summary>
/// <remarks>
/// Based on http://stackoverflow.com/questions/5343006/is-there-a-c-sharp-type-for-representing-an-integer-range
/// </remarks>
public struct Range<T>
{
private static readonly Comparer<T> _comparer = Comparer<T>.Default;

/// <summary>
/// Returns minimum value of the range.
/// Возвращает минимальное значение диапазона.
/// </summary>
public readonly T Minimum;

/// <summary>
/// Returns maximum value of the range.
/// Возвращает максимальное значение диапазона.
/// </summary>
public readonly T Maximum;

public Range(T minimumAndMaximum)
{
Minimum = minimumAndMaximum;
Maximum = minimumAndMaximum;
}

public Range(T minimum, T maximum)
{
Minimum = minimum;
Maximum = maximum;
}

/// <summary>
/// Presents the Range in readable format.
/// Представляет диапазон в удобном для чтения формате.
/// </summary>
/// <returns>String representation of the Range. Строковое представление диапазона.</returns>
public override string ToString() => $"[{Minimum}, {Maximum}]";

/// <summary>
/// Determines if the range is valid. Определяет, является ли диапазон корректным.
/// </summary>
/// <returns>True if range is valid, else false. True, если диапазон корректный, иначе false.</returns>
public bool IsValid() => _comparer.Compare(Minimum, Maximum) <= 0;

/// <summary>
/// Determines if the provided value is inside the range.
/// Определяет, находится ли указанное значение внутри диапазона.
/// </summary>
/// <param name="value">The value to test. Значение для проверки.</param>
/// <returns>True if the value is inside Range, else false. True, если значение находится внутри диапазона, иначе false.</returns>
public bool ContainsValue(T value) => _comparer.Compare(Minimum, value) <= 0 && _comparer.Compare(Maximum, value) >= 0;

/// <summary>
/// Determines if this Range is inside the bounds of another range.
/// Определяет, находится ли этот диапазон в пределах другого диапазона.
/// </summary>
/// <param name="range">The parent range to test on. Родительский диапазон для проверки.</param>
/// <returns>True if range is inclusive, else false. True, если диапазон включен, иначе false.</returns>
public bool IsInsideRange(Range<T> range) => range.ContainsRange(this);

/// <summary>
/// Determines if another range is inside the bounds of this range.
/// Определяет, находится ли другой диапазон внутри границ этого диапазона.
/// </summary>
/// <param name="range">The child range to test. Дочерний диапазон для проверки.</param>
/// <returns>True if range is inside, else false. True, если диапазон находится внутри, иначе false.</returns>
public bool ContainsRange(Range<T> range) => IsValid() && range.IsValid() && ContainsValue(range.Minimum) && ContainsValue(range.Maximum);
}
}
8 changes: 8 additions & 0 deletions push-nuget.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dotnet pack -c Release --include-symbols
cd bin\Release
dotnet nuget push -s https://api.nuget.org/v3/index.json *.symbols.nupkg
del *.symbols.nupkg
dotnet nuget push -s https://api.nuget.org/v3/index.json *.nupkg
del *.nupkg
cd ..
cd ..

1 comment on commit 505d917

@Konard
Copy link
Member Author

@Konard Konard commented on 505d917 Jul 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.