From 636688cda0963b545cb3dcfeb8c690ff43080b1d Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 18 Aug 2019 17:48:06 +0200 Subject: [PATCH] use shared guard --- SixLabors.Shapes.sln.DotSettings | 1 + .../SixLabors.Shapes.Text.csproj | 4 + src/SixLabors.Shapes/Helpers/Guard.cs | 118 ------------------ src/SixLabors.Shapes/SixLabors.Shapes.csproj | 4 + standards | 2 +- 5 files changed, 10 insertions(+), 119 deletions(-) delete mode 100644 src/SixLabors.Shapes/Helpers/Guard.cs diff --git a/SixLabors.Shapes.sln.DotSettings b/SixLabors.Shapes.sln.DotSettings index 90b24d4..4a116aa 100644 --- a/SixLabors.Shapes.sln.DotSettings +++ b/SixLabors.Shapes.sln.DotSettings @@ -384,6 +384,7 @@ True True True + True True True True diff --git a/src/SixLabors.Shapes.Text/SixLabors.Shapes.Text.csproj b/src/SixLabors.Shapes.Text/SixLabors.Shapes.Text.csproj index bedd304..627434b 100644 --- a/src/SixLabors.Shapes.Text/SixLabors.Shapes.Text.csproj +++ b/src/SixLabors.Shapes.Text/SixLabors.Shapes.Text.csproj @@ -31,6 +31,10 @@ + + + + ..\..\standards\SixLabors.ruleset diff --git a/src/SixLabors.Shapes/Helpers/Guard.cs b/src/SixLabors.Shapes/Helpers/Guard.cs deleted file mode 100644 index 006eda7..0000000 --- a/src/SixLabors.Shapes/Helpers/Guard.cs +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics; - -namespace SixLabors.Shapes -{ - /// - /// Provides methods to protect against invalid parameters. - /// - [DebuggerStepThrough] - internal static class Guard - { - /// - /// Verifies that the specified value is less than a maximum value - /// and throws an exception if it is not. - /// - /// The target value, which should be validated. - /// The maximum value. - /// The name of the parameter that is to be checked. - /// The type of the value. - /// - /// is greater than the maximum value. - /// - public static void MustBeLessThan(TValue value, TValue max, string parameterName) - where TValue : IComparable - { - if (value.CompareTo(max) >= 0) - { - throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than {max}."); - } - } - - /// - /// Verifies that the specified value is less than or equal to a maximum value - /// and throws an exception if it is not. - /// - /// The target value, which should be validated. - /// The maximum value. - /// The name of the parameter that is to be checked. - /// The type of the value. - /// - /// is greater than the maximum value. - /// - public static void MustBeLessThanOrEqualTo(TValue value, TValue max, string parameterName) - where TValue : IComparable - { - if (value.CompareTo(max) > 0) - { - throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than or equal to {max}."); - } - } - - /// - /// Verifies that the specified value is greater than a minimum value - /// and throws an exception if it is not. - /// - /// The target value, which should be validated. - /// The minimum value. - /// The name of the parameter that is to be checked. - /// The type of the value. - /// - /// is less than the minimum value. - /// - public static void MustBeGreaterThan(TValue value, TValue min, string parameterName) - where TValue : IComparable - { - if (value.CompareTo(min) <= 0) - { - throw new ArgumentOutOfRangeException( - parameterName, - $"Value must be greater than {min}."); - } - } - - /// - /// Verifies that the specified value is greater than or equal to a minimum value - /// and throws an exception if it is not. - /// - /// The target value, which should be validated. - /// The minimum value. - /// The name of the parameter that is to be checked. - /// The type of the value. - /// - /// is less than the minimum value. - /// - public static void MustBeGreaterThanOrEqualTo(TValue value, TValue min, string parameterName) - where TValue : IComparable - { - if (value.CompareTo(min) < 0) - { - throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min}."); - } - } - - /// - /// Verifies that the specified value is greater than or equal to a minimum value and less than - /// or equal to a maximum value and throws an exception if it is not. - /// - /// The target value, which should be validated. - /// The minimum value. - /// The maximum value. - /// The name of the parameter that is to be checked. - /// The type of the value. - /// - /// is less than the minimum value of greater than the maximum value. - /// - public static void MustBeBetweenOrEqualTo(TValue value, TValue min, TValue max, string parameterName) - where TValue : IComparable - { - if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) - { - throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min} and less than or equal to {max}."); - } - } - } -} \ No newline at end of file diff --git a/src/SixLabors.Shapes/SixLabors.Shapes.csproj b/src/SixLabors.Shapes/SixLabors.Shapes.csproj index 9be79e5..39ae182 100644 --- a/src/SixLabors.Shapes/SixLabors.Shapes.csproj +++ b/src/SixLabors.Shapes/SixLabors.Shapes.csproj @@ -31,6 +31,10 @@ + + + + diff --git a/standards b/standards index dd83f64..948a029 160000 --- a/standards +++ b/standards @@ -1 +1 @@ -Subproject commit dd83f649638c6333984a757c01be6ec294e6b63c +Subproject commit 948a02984c6b62dca1c40b02b289f6d1c13d79b1