From 2ae07032a6aac3fadf59ffb348f4cbaf128ed4bb Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 13:34:24 +0000 Subject: [PATCH 01/14] Bugfix T4 multiple file generation for VS2019+ --- DNX.Helpers/MultipleOutputHelper.ttinclude | 2 +- Test.DNX.Helpers/MultipleOutputHelper.ttinclude | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DNX.Helpers/MultipleOutputHelper.ttinclude b/DNX.Helpers/MultipleOutputHelper.ttinclude index b497138..450bd30 100644 --- a/DNX.Helpers/MultipleOutputHelper.ttinclude +++ b/DNX.Helpers/MultipleOutputHelper.ttinclude @@ -131,7 +131,7 @@ class Manager { return; base.Process(split, sync); if (sync) - projectSyncAction.EndInvoke(projectSyncAction.BeginInvoke(generatedFileNames, null, null)); + projectSyncAction(generatedFileNames); } protected override void CreateFile(String fileName, String content) { diff --git a/Test.DNX.Helpers/MultipleOutputHelper.ttinclude b/Test.DNX.Helpers/MultipleOutputHelper.ttinclude index b497138..450bd30 100644 --- a/Test.DNX.Helpers/MultipleOutputHelper.ttinclude +++ b/Test.DNX.Helpers/MultipleOutputHelper.ttinclude @@ -131,7 +131,7 @@ class Manager { return; base.Process(split, sync); if (sync) - projectSyncAction.EndInvoke(projectSyncAction.BeginInvoke(generatedFileNames, null, null)); + projectSyncAction(generatedFileNames); } protected override void CreateFile(String fileName, String content) { From 565a338e66604141473ed76f41374e597f024b1f Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 13:36:00 +0000 Subject: [PATCH 02/14] Remove file no longer needed --- DNX.Helpers/Converters/BuiltInTypes/Build.cmd | 52 ++-- DNX.Helpers/DNX.Helpers.rctob | 2 - DNX.Helpers/MultipleOutputHelper1.cs | 1 - DNX.Helpers/Properties/AssemblyInfo.cs | 35 --- .../GuardByteBulitInTypes.generated.cs | 228 ------------------ .../GuardDateTimeBulitInTypes.generated.cs | 228 ------------------ .../GuardDecimalBulitInTypes.generated.cs | 228 ------------------ .../GuardDoubleBulitInTypes.generated.cs | 228 ------------------ .../GuardFloatBulitInTypes.generated.cs | 228 ------------------ .../GuardInt16BulitInTypes.generated.cs | 228 ------------------ .../GuardInt32BulitInTypes.generated.cs | 228 ------------------ .../GuardInt64BulitInTypes.generated.cs | 228 ------------------ .../GuardSByteBulitInTypes.generated.cs | 228 ------------------ .../GuardUInt16BulitInTypes.generated.cs | 228 ------------------ .../GuardUInt32BulitInTypes.generated.cs | 228 ------------------ .../GuardUInt64BulitInTypes.generated.cs | 228 ------------------ 16 files changed, 26 insertions(+), 2800 deletions(-) delete mode 100644 DNX.Helpers/DNX.Helpers.rctob delete mode 100644 DNX.Helpers/MultipleOutputHelper1.cs delete mode 100644 DNX.Helpers/Properties/AssemblyInfo.cs delete mode 100644 DNX.Helpers/Validation/GuardByteBulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardDateTimeBulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardDecimalBulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardDoubleBulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardFloatBulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardInt16BulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardInt32BulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardInt64BulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardSByteBulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardUInt16BulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardUInt32BulitInTypes.generated.cs delete mode 100644 DNX.Helpers/Validation/GuardUInt64BulitInTypes.generated.cs diff --git a/DNX.Helpers/Converters/BuiltInTypes/Build.cmd b/DNX.Helpers/Converters/BuiltInTypes/Build.cmd index cbf5345..b333070 100644 --- a/DNX.Helpers/Converters/BuiltInTypes/Build.cmd +++ b/DNX.Helpers/Converters/BuiltInTypes/Build.cmd @@ -4,32 +4,32 @@ SETLOCAL EnableDelayedExpansion REM :BuildTemplate C#-Type Descriptive-Name -REM CALL :BuildTemplate bool Bool -REM -REM CALL :BuildTemplate byte Byte -REM CALL :BuildTemplate sbyte SByte -REM -REM CALL :BuildTemplate DateTime DateTime -REM -REM CALL :BuildTemplate short Int16 -REM CALL :BuildTemplate ushort UInt16 -REM CALL :BuildTemplate short Short -REM CALL :BuildTemplate ushort UShort -REM -REM CALL :BuildTemplate int Int32 -REM CALL :BuildTemplate uint UInt32 -REM CALL :BuildTemplate int Int -REM CALL :BuildTemplate uint UInt -REM -REM CALL :BuildTemplate long Int64 -REM CALL :BuildTemplate ulong UInt64 -REM CALL :BuildTemplate long Long -REM CALL :BuildTemplate ulong ULong -REM -REM CALL :BuildTemplate float Float -REM CALL :BuildTemplate float Single -REM CALL :BuildTemplate double Double -REM CALL :BuildTemplate decimal Decimal +CALL :BuildTemplate bool Bool + +CALL :BuildTemplate byte Byte +CALL :BuildTemplate sbyte SByte + +CALL :BuildTemplate DateTime DateTime + +CALL :BuildTemplate short Int16 +CALL :BuildTemplate ushort UInt16 +CALL :BuildTemplate short Short +CALL :BuildTemplate ushort UShort + +CALL :BuildTemplate int Int32 +CALL :BuildTemplate uint UInt32 +CALL :BuildTemplate int Int +CALL :BuildTemplate uint UInt + +CALL :BuildTemplate long Int64 +CALL :BuildTemplate ulong UInt64 +CALL :BuildTemplate long Long +CALL :BuildTemplate ulong ULong + +CALL :BuildTemplate float Float +CALL :BuildTemplate float Single +CALL :BuildTemplate double Double +CALL :BuildTemplate decimal Decimal GOTO :EOF diff --git a/DNX.Helpers/DNX.Helpers.rctob b/DNX.Helpers/DNX.Helpers.rctob deleted file mode 100644 index 8bd0ff4..0000000 --- a/DNX.Helpers/DNX.Helpers.rctob +++ /dev/null @@ -1,2 +0,0 @@ -C:\Users\martin.smith\Dev\github\martinsmith1968\DNX.Helpers\DNX.Helpers.sln -Debug \ No newline at end of file diff --git a/DNX.Helpers/MultipleOutputHelper1.cs b/DNX.Helpers/MultipleOutputHelper1.cs deleted file mode 100644 index 5f28270..0000000 --- a/DNX.Helpers/MultipleOutputHelper1.cs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/DNX.Helpers/Properties/AssemblyInfo.cs b/DNX.Helpers/Properties/AssemblyInfo.cs deleted file mode 100644 index 046702a..0000000 --- a/DNX.Helpers/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("DNX.Helpers")] -[assembly: AssemblyDescription(".NET Extensions and helpers for Core and Common .NET types")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("DNX Solutions Ltd")] -[assembly: AssemblyProduct("DNX.Helpers")] -[assembly: AssemblyCopyright("Copyright © 2016 DNX Solutions Ltd")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("d0c74fda-2cde-4e24-89f5-a5fc97d5c85c")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.2.*")] -[assembly: AssemblyFileVersion("1.2.2.0")] diff --git a/DNX.Helpers/Validation/GuardByteBulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardByteBulitInTypes.generated.cs deleted file mode 100644 index 9544f43..0000000 --- a/DNX.Helpers/Validation/GuardByteBulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, byte min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, byte val, byte min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, byte min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, byte val, byte min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, byte max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, byte val, byte max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, byte max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, byte val, byte max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, byte min, byte max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, byte min, byte max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, byte bound1, byte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, byte val, byte bound1, byte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsByteExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsByteExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardDateTimeBulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardDateTimeBulitInTypes.generated.cs deleted file mode 100644 index ac9c5e7..0000000 --- a/DNX.Helpers/Validation/GuardDateTimeBulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, DateTime min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, DateTime val, DateTime min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, DateTime min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, DateTime val, DateTime min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, DateTime max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, DateTime val, DateTime max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, DateTime max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, DateTime val, DateTime max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, DateTime min, DateTime max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, DateTime min, DateTime max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, DateTime bound1, DateTime bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, DateTime val, DateTime bound1, DateTime bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsDateTimeExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsDateTimeExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardDecimalBulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardDecimalBulitInTypes.generated.cs deleted file mode 100644 index ca95b77..0000000 --- a/DNX.Helpers/Validation/GuardDecimalBulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, decimal min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, decimal val, decimal min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, decimal min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, decimal val, decimal min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, decimal max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, decimal val, decimal max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, decimal max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, decimal val, decimal max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, decimal min, decimal max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, decimal min, decimal max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, decimal bound1, decimal bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, decimal val, decimal bound1, decimal bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsDecimalExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsDecimalExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardDoubleBulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardDoubleBulitInTypes.generated.cs deleted file mode 100644 index e592f26..0000000 --- a/DNX.Helpers/Validation/GuardDoubleBulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, double min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, double val, double min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, double min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, double val, double min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, double max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, double val, double max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, double max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, double val, double max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, double min, double max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, double min, double max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, double bound1, double bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, double val, double bound1, double bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsDoubleExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsDoubleExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardFloatBulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardFloatBulitInTypes.generated.cs deleted file mode 100644 index 10fa141..0000000 --- a/DNX.Helpers/Validation/GuardFloatBulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, float min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, float val, float min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, float min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, float val, float min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, float max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, float val, float max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, float max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, float val, float max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, float min, float max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, float min, float max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, float bound1, float bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, float val, float bound1, float bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsFloatExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsFloatExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardInt16BulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardInt16BulitInTypes.generated.cs deleted file mode 100644 index efbf9f3..0000000 --- a/DNX.Helpers/Validation/GuardInt16BulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, short min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, short val, short min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, short min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, short val, short min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, short max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, short val, short max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, short max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, short val, short max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, short min, short max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, short min, short max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, short bound1, short bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, short val, short bound1, short bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsInt16Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsInt16Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardInt32BulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardInt32BulitInTypes.generated.cs deleted file mode 100644 index c8b6d6c..0000000 --- a/DNX.Helpers/Validation/GuardInt32BulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, int min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, int val, int min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, int min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, int val, int min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, int max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, int val, int max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, int max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, int val, int max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, int min, int max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, int min, int max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, int bound1, int bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, int val, int bound1, int bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsInt32Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsInt32Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardInt64BulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardInt64BulitInTypes.generated.cs deleted file mode 100644 index 51ccf23..0000000 --- a/DNX.Helpers/Validation/GuardInt64BulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, long min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, long val, long min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, long min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, long val, long min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, long max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, long val, long max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, long max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, long val, long max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, long min, long max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, long min, long max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, long bound1, long bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, long val, long bound1, long bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsInt64Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsInt64Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardSByteBulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardSByteBulitInTypes.generated.cs deleted file mode 100644 index 8853158..0000000 --- a/DNX.Helpers/Validation/GuardSByteBulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, sbyte min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, sbyte val, sbyte min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, sbyte min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, sbyte val, sbyte min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, sbyte max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, sbyte val, sbyte max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, sbyte max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, sbyte val, sbyte max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, sbyte min, sbyte max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, sbyte min, sbyte max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, sbyte bound1, sbyte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, sbyte val, sbyte bound1, sbyte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsSByteExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsSByteExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardUInt16BulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardUInt16BulitInTypes.generated.cs deleted file mode 100644 index 53e96ad..0000000 --- a/DNX.Helpers/Validation/GuardUInt16BulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, ushort min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, ushort val, ushort min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, ushort min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, ushort val, ushort min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, ushort max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, ushort val, ushort max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, ushort max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, ushort val, ushort max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, ushort min, ushort max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, ushort min, ushort max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, ushort bound1, ushort bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, ushort val, ushort bound1, ushort bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsUInt16Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsUInt16Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardUInt32BulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardUInt32BulitInTypes.generated.cs deleted file mode 100644 index c6ebabf..0000000 --- a/DNX.Helpers/Validation/GuardUInt32BulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, uint min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, uint val, uint min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, uint min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, uint val, uint min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, uint max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, uint val, uint max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, uint max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, uint val, uint max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, uint min, uint max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, uint min, uint max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, uint bound1, uint bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, uint val, uint bound1, uint bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsUInt32Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsUInt32Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} diff --git a/DNX.Helpers/Validation/GuardUInt64BulitInTypes.generated.cs b/DNX.Helpers/Validation/GuardUInt64BulitInTypes.generated.cs deleted file mode 100644 index 929e885..0000000 --- a/DNX.Helpers/Validation/GuardUInt64BulitInTypes.generated.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Code generated by a Template -using System; -using System.Linq.Expressions; -using DNX.Helpers.Maths; -using DNX.Helpers.Maths.BuiltInTypes; -using DNX.Helpers.Reflection; - -namespace DNX.Helpers.Validation -{ - /// - /// Guard Extensions. - /// - public static partial class Guard - { - /// - /// Ensures the expression evaluates to greater than the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThan(Expression> exp, ulong min) - { - IsGreaterThan(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThan(Expression> exp, ulong val, ulong min) - { - if (val > min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The minimum. - public static void IsGreaterThanOrEqualTo(Expression> exp, ulong min) - { - IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); - } - - /// - /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsGreaterThanOrEqualTo(Expression> exp, ulong val, ulong min) - { - if (val >= min) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be greater than or equal to {1}", - memberName, - min - ) - ); - } - - /// - /// Ensures the expression evaluates to less than the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThan(Expression> exp, ulong max) - { - IsLessThan(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than the specified minimum - /// - /// The exp. - /// The value. - /// The minimum. - /// - public static void IsLessThan(Expression> exp, ulong val, ulong max) - { - if (val < max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The maximum. - public static void IsLessThanOrEqualTo(Expression> exp, ulong max) - { - IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); - } - - /// - /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum - /// - /// The exp. - /// The value. - /// The maximum. - /// - public static void IsLessThanOrEqualTo(Expression> exp, ulong val, ulong max) - { - if (val <= max) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be less than or equal to {1}", - memberName, - max - ) - ); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The linq expression of the argument to check - /// minimum allowed value - /// maximum allowed value - public static void IsBetween(Expression> exp, ulong min, ulong max) - { - IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The minimum. - /// The maximum. - /// Type of the bounds. - public static void IsBetween(Expression> exp, ulong min, ulong max, IsBetweenBoundsType boundsType) - { - IsBetween(exp, min, max, false, boundsType); - } - - /// - /// Ensures the expression evaluates to between the specified values - /// - /// The exp. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - public static void IsBetween(Expression> exp, ulong bound1, ulong bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); - } - - /// - /// Ensures the expression and corresponding value evaluates to between the specified values - /// - /// The exp. - /// The value. - /// The bound1. - /// The bound2. - /// if set to true [allow either order]. - /// Type of the bounds. - /// - /// - public static void IsBetween(Expression> exp, ulong val, ulong bound1, ulong bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) - { - if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) - { - return; - } - - var memberName = ExpressionExtensions.GetMemberName(exp); - - throw new ArgumentOutOfRangeException( - memberName, - val, - string.Format("{0} must be {1}", - memberName, - string.Format(boundsType.GetLimitDescriptionFormat(), - MathsUInt64Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), - MathsUInt64Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) - ) - ) - ); - } - } -} From e59965e37e7b9721b24cca891b91603730a8a447 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 13:36:20 +0000 Subject: [PATCH 03/14] Template patches --- .../BuiltInTypes/MathExtensions.cs.template | 2 +- .../Validation/GuardBuiltInTypesTemplate.tt | 4 +- .../GuardByteBuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardDateTimeBuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardDecimalBuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardDoubleBuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardFloatBuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardInt16BuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardInt32BuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardInt64BuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardSByteBuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardUInt16BuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardUInt32BuiltInTypes.generated.cs | 228 ++++++++++++++++++ .../GuardUInt64BuiltInTypes.generated.cs | 228 ++++++++++++++++++ 14 files changed, 2739 insertions(+), 3 deletions(-) create mode 100644 DNX.Helpers/Validation/GuardByteBuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardDateTimeBuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardDecimalBuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardDoubleBuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardFloatBuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardInt16BuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardInt32BuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardInt64BuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardSByteBuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardUInt16BuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardUInt32BuiltInTypes.generated.cs create mode 100644 DNX.Helpers/Validation/GuardUInt64BuiltInTypes.generated.cs diff --git a/DNX.Helpers/Maths/BuiltInTypes/MathExtensions.cs.template b/DNX.Helpers/Maths/BuiltInTypes/MathExtensions.cs.template index ba9dee8..38a15ad 100644 --- a/DNX.Helpers/Maths/BuiltInTypes/MathExtensions.cs.template +++ b/DNX.Helpers/Maths/BuiltInTypes/MathExtensions.cs.template @@ -67,7 +67,7 @@ namespace DNX.Helpers.Maths.BuiltInTypes /// Control boundary checking. /// /// true if the specified minimum is between min and max; otherwise, false. - /// + /// public static bool IsBetween(this #type# value, #type# min, #type# max, bool allowEitherOrder, IsBetweenBoundsType boundsType) { var lowerBound = GetLowerBound(min, max, allowEitherOrder); diff --git a/DNX.Helpers/Validation/GuardBuiltInTypesTemplate.tt b/DNX.Helpers/Validation/GuardBuiltInTypesTemplate.tt index 6782f3f..b20afa6 100644 --- a/DNX.Helpers/Validation/GuardBuiltInTypesTemplate.tt +++ b/DNX.Helpers/Validation/GuardBuiltInTypesTemplate.tt @@ -42,7 +42,7 @@ foreach (var kvp in types) { var typeName = kvp.Value; var typeDesc = kvp.Key; - var fileName = string.Format("Guard{0}BulitInTypes.generated.cs", typeDesc); + var fileName = string.Format("Guard{0}BuiltInTypes.generated.cs", typeDesc); manager.StartNewFile(fileName); #> @@ -99,7 +99,7 @@ foreach (var kvp in types) /// /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum - /// + /// /// The exp. /// The value. /// The minimum. diff --git a/DNX.Helpers/Validation/GuardByteBuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardByteBuiltInTypes.generated.cs new file mode 100644 index 0000000..16bb570 --- /dev/null +++ b/DNX.Helpers/Validation/GuardByteBuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, byte min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, byte val, byte min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, byte min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, byte val, byte min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, byte max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, byte val, byte max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, byte max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, byte val, byte max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, byte min, byte max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, byte min, byte max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, byte bound1, byte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, byte val, byte bound1, byte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsByteExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsByteExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardDateTimeBuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardDateTimeBuiltInTypes.generated.cs new file mode 100644 index 0000000..d8bd107 --- /dev/null +++ b/DNX.Helpers/Validation/GuardDateTimeBuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, DateTime min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, DateTime val, DateTime min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, DateTime min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, DateTime val, DateTime min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, DateTime max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, DateTime val, DateTime max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, DateTime max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, DateTime val, DateTime max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, DateTime min, DateTime max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, DateTime min, DateTime max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, DateTime bound1, DateTime bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, DateTime val, DateTime bound1, DateTime bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsDateTimeExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsDateTimeExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardDecimalBuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardDecimalBuiltInTypes.generated.cs new file mode 100644 index 0000000..f50a8df --- /dev/null +++ b/DNX.Helpers/Validation/GuardDecimalBuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, decimal min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, decimal val, decimal min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, decimal min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, decimal val, decimal min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, decimal max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, decimal val, decimal max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, decimal max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, decimal val, decimal max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, decimal min, decimal max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, decimal min, decimal max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, decimal bound1, decimal bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, decimal val, decimal bound1, decimal bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsDecimalExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsDecimalExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardDoubleBuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardDoubleBuiltInTypes.generated.cs new file mode 100644 index 0000000..3ff591c --- /dev/null +++ b/DNX.Helpers/Validation/GuardDoubleBuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, double min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, double val, double min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, double min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, double val, double min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, double max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, double val, double max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, double max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, double val, double max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, double min, double max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, double min, double max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, double bound1, double bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, double val, double bound1, double bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsDoubleExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsDoubleExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardFloatBuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardFloatBuiltInTypes.generated.cs new file mode 100644 index 0000000..3835cb7 --- /dev/null +++ b/DNX.Helpers/Validation/GuardFloatBuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, float min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, float val, float min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, float min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, float val, float min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, float max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, float val, float max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, float max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, float val, float max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, float min, float max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, float min, float max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, float bound1, float bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, float val, float bound1, float bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsFloatExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsFloatExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardInt16BuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardInt16BuiltInTypes.generated.cs new file mode 100644 index 0000000..ebbff3f --- /dev/null +++ b/DNX.Helpers/Validation/GuardInt16BuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, short min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, short val, short min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, short min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, short val, short min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, short max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, short val, short max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, short max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, short val, short max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, short min, short max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, short min, short max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, short bound1, short bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, short val, short bound1, short bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsInt16Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsInt16Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardInt32BuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardInt32BuiltInTypes.generated.cs new file mode 100644 index 0000000..b21f82d --- /dev/null +++ b/DNX.Helpers/Validation/GuardInt32BuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, int min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, int val, int min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, int min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, int val, int min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, int max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, int val, int max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, int max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, int val, int max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, int min, int max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, int min, int max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, int bound1, int bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, int val, int bound1, int bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsInt32Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsInt32Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardInt64BuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardInt64BuiltInTypes.generated.cs new file mode 100644 index 0000000..e8ec599 --- /dev/null +++ b/DNX.Helpers/Validation/GuardInt64BuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, long min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, long val, long min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, long min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, long val, long min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, long max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, long val, long max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, long max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, long val, long max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, long min, long max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, long min, long max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, long bound1, long bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, long val, long bound1, long bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsInt64Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsInt64Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardSByteBuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardSByteBuiltInTypes.generated.cs new file mode 100644 index 0000000..fedc115 --- /dev/null +++ b/DNX.Helpers/Validation/GuardSByteBuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, sbyte min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, sbyte val, sbyte min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, sbyte min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, sbyte val, sbyte min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, sbyte max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, sbyte val, sbyte max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, sbyte max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, sbyte val, sbyte max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, sbyte min, sbyte max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, sbyte min, sbyte max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, sbyte bound1, sbyte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, sbyte val, sbyte bound1, sbyte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsSByteExtensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsSByteExtensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardUInt16BuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardUInt16BuiltInTypes.generated.cs new file mode 100644 index 0000000..d129a9a --- /dev/null +++ b/DNX.Helpers/Validation/GuardUInt16BuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, ushort min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, ushort val, ushort min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, ushort min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, ushort val, ushort min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, ushort max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, ushort val, ushort max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, ushort max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, ushort val, ushort max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, ushort min, ushort max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, ushort min, ushort max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, ushort bound1, ushort bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, ushort val, ushort bound1, ushort bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsUInt16Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsUInt16Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardUInt32BuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardUInt32BuiltInTypes.generated.cs new file mode 100644 index 0000000..3727466 --- /dev/null +++ b/DNX.Helpers/Validation/GuardUInt32BuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, uint min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, uint val, uint min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, uint min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, uint val, uint min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, uint max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, uint val, uint max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, uint max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, uint val, uint max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, uint min, uint max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, uint min, uint max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, uint bound1, uint bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, uint val, uint bound1, uint bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsUInt32Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsUInt32Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} diff --git a/DNX.Helpers/Validation/GuardUInt64BuiltInTypes.generated.cs b/DNX.Helpers/Validation/GuardUInt64BuiltInTypes.generated.cs new file mode 100644 index 0000000..e6ef1b6 --- /dev/null +++ b/DNX.Helpers/Validation/GuardUInt64BuiltInTypes.generated.cs @@ -0,0 +1,228 @@ +// Code generated by a Template +using System; +using System.Linq.Expressions; +using DNX.Helpers.Maths; +using DNX.Helpers.Maths.BuiltInTypes; +using DNX.Helpers.Reflection; + +namespace DNX.Helpers.Validation +{ + /// + /// Guard Extensions. + /// + public static partial class Guard + { + /// + /// Ensures the expression evaluates to greater than the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThan(Expression> exp, ulong min) + { + IsGreaterThan(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThan(Expression> exp, ulong val, ulong min) + { + if (val > min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The minimum. + public static void IsGreaterThanOrEqualTo(Expression> exp, ulong min) + { + IsGreaterThanOrEqualTo(exp, exp.Compile().Invoke(), min); + } + + /// + /// Ensures the expression and corresponding value evaluates to greater than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsGreaterThanOrEqualTo(Expression> exp, ulong val, ulong min) + { + if (val >= min) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be greater than or equal to {1}", + memberName, + min + ) + ); + } + + /// + /// Ensures the expression evaluates to less than the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThan(Expression> exp, ulong max) + { + IsLessThan(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than the specified minimum + /// + /// The exp. + /// The value. + /// The minimum. + /// + public static void IsLessThan(Expression> exp, ulong val, ulong max) + { + if (val < max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The maximum. + public static void IsLessThanOrEqualTo(Expression> exp, ulong max) + { + IsLessThanOrEqualTo(exp, exp.Compile().Invoke(), max); + } + + /// + /// Ensures the expression and corresponding value evaluates to less than or equal to the specified minimum + /// + /// The exp. + /// The value. + /// The maximum. + /// + public static void IsLessThanOrEqualTo(Expression> exp, ulong val, ulong max) + { + if (val <= max) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be less than or equal to {1}", + memberName, + max + ) + ); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The linq expression of the argument to check + /// minimum allowed value + /// maximum allowed value + public static void IsBetween(Expression> exp, ulong min, ulong max) + { + IsBetween(exp, min, max, IsBetweenBoundsType.Inclusive); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The minimum. + /// The maximum. + /// Type of the bounds. + public static void IsBetween(Expression> exp, ulong min, ulong max, IsBetweenBoundsType boundsType) + { + IsBetween(exp, min, max, false, boundsType); + } + + /// + /// Ensures the expression evaluates to between the specified values + /// + /// The exp. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + public static void IsBetween(Expression> exp, ulong bound1, ulong bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType); + } + + /// + /// Ensures the expression and corresponding value evaluates to between the specified values + /// + /// The exp. + /// The value. + /// The bound1. + /// The bound2. + /// if set to true [allow either order]. + /// Type of the bounds. + /// + /// + public static void IsBetween(Expression> exp, ulong val, ulong bound1, ulong bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType) + { + if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType)) + { + return; + } + + var memberName = ExpressionExtensions.GetMemberName(exp); + + throw new ArgumentOutOfRangeException( + memberName, + val, + string.Format("{0} must be {1}", + memberName, + string.Format(boundsType.GetLimitDescriptionFormat(), + MathsUInt64Extensions.GetLowerBound(bound1, bound2, allowEitherOrder), + MathsUInt64Extensions.GetUpperBound(bound1, bound2, allowEitherOrder) + ) + ) + ); + } + } +} From 237d1c4e455f7615e1a3b0526e905d706755bcb6 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 13:36:46 +0000 Subject: [PATCH 04/14] New csproj format --- DNX.Helpers/DNX.Helpers.csproj | 318 +++++---------------------------- 1 file changed, 49 insertions(+), 269 deletions(-) diff --git a/DNX.Helpers/DNX.Helpers.csproj b/DNX.Helpers/DNX.Helpers.csproj index 37ba257..ae6f7ad 100644 --- a/DNX.Helpers/DNX.Helpers.csproj +++ b/DNX.Helpers/DNX.Helpers.csproj @@ -1,289 +1,69 @@ - - - + - Debug - AnyCPU - {BC278532-83D1-4AC0-BA01-E16F237BCBF9} - Library - Properties - DNX.Helpers - DNX.Helpers - v4.5.2 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\DNX.Helpers.XML - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\DNX.Helpers.XML + netstandard2.0 + true + .NET Extensions and helpers for Core and Common .NET types + Martin Smith + Copyright © 2016-2019 DNX Solutions Ltd + licence.txt + https://github.com/martinsmith1968/DNX.Helpers + true + favicon-32x32.png + + DNX helpers extensions string array linq + Interpolation to a working version and some preparation for moving to .NET Standard + 2.0.0 + 1.2.2.0 - - - + + + + - - - - - - - - - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - True - True - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - - - - - - - - - - - - - - - - - - - - - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - True - True - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - MathsExtensionsTemplate.tt - - - - MultipleOutputHelper.ttinclude - True - True - - - - - - - - - - - - - - - - - - - - - - - - True - True - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - GuardBuiltInTypesTemplate.tt - - - - + - + TextTemplatingFileGenerator ConvertExtensionsTemplate.cs - True - True - True - - + TextTemplatingFileGenerator MathsExtensionsTemplate.cs - True - True - True - - TextTemplatingFileGenerator - MultipleOutputHelper1.cs - - + TextTemplatingFileGenerator GuardBuiltInTypesTemplate.cs - True - True - True + + True + + + + True + + + + + - + + True + True + ConvertExtensionsTemplate.tt + + + True + True + MathsExtensionsTemplate.tt + + + True + True + GuardBuiltInTypesTemplate.tt + - - \ No newline at end of file From 41f3d53e4d022d9eca97ebf8e5287db28807d76d Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 13:38:37 +0000 Subject: [PATCH 05/14] Remove deploy.sh file no longer needed --- .travis.yml | 2 +- DNX.Helpers.sln | 3 +-- deploy.sh | 6 ------ 3 files changed, 2 insertions(+), 9 deletions(-) delete mode 100644 deploy.sh diff --git a/.travis.yml b/.travis.yml index 3360899..abe7e47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,6 @@ script: deploy: skip_cleanup: true provider: script - script: chmod +x ./deploy.sh && ./deploy.sh $APPNAME $NUGET_API_URL $NUGET_API_KEY + script: nuget push $APPNAME.*.nupkg -Source $NUGET_API_URL -ApiKey $NUGET_API_KEY on: branch: master diff --git a/DNX.Helpers.sln b/DNX.Helpers.sln index e4e7080..74e3435 100644 --- a/DNX.Helpers.sln +++ b/DNX.Helpers.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29519.181 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DNX.Helpers", "DNX.Helpers\DNX.Helpers.csproj", "{BC278532-83D1-4AC0-BA01-E16F237BCBF9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DNX.Helpers", "DNX.Helpers\DNX.Helpers.csproj", "{BC278532-83D1-4AC0-BA01-E16F237BCBF9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.DNX.Helpers", "Test.DNX.Helpers\Test.DNX.Helpers.csproj", "{B3666B7C-ADF3-46B1-8955-D3224F4A9C8D}" EndProject @@ -25,7 +25,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".commands", ".commands", "{FB47A44B-A670-480D-8B11-6D02072596D4}" ProjectSection(SolutionItems) = preProject commands.json = commands.json - deploy.sh = deploy.sh GenerateMarkdown.cmd = GenerateMarkdown.cmd NuGet.Pack.cmd = NuGet.Pack.cmd NuGet.Push.cmd = NuGet.Push.cmd diff --git a/deploy.sh b/deploy.sh deleted file mode 100644 index 0188d59..0000000 --- a/deploy.sh +++ /dev/null @@ -1,6 +0,0 @@ -APPNAME=$1 -NUGET_API_URL=$2 -NUGET_API_KEY=$3 - -echo nuget push $APPNAME.*.nupkg -Source $NUGET_API_URL -ApiKey secret -nuget push $APPNAME.*.nupkg -Source $NUGET_API_URL -ApiKey $NUGET_API_KEY From 4e96427b746c144519cd30af9bc31e7f1a5ffa21 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 20:14:41 +0000 Subject: [PATCH 06/14] Removed old files --- Test.DNX.Helpers/MultipleOutputHelper1.cs | 1 - Test.DNX.Helpers/Properties/AssemblyInfo.cs | 36 --- Test.DNX.Helpers/Test.DNX.Helpers.rctob | 2 - .../Validation/GuardBuiltInTypesTests-Old.cs | 227 ------------------ packages/repositories.config | 4 - 5 files changed, 270 deletions(-) delete mode 100644 Test.DNX.Helpers/MultipleOutputHelper1.cs delete mode 100644 Test.DNX.Helpers/Properties/AssemblyInfo.cs delete mode 100644 Test.DNX.Helpers/Test.DNX.Helpers.rctob delete mode 100644 Test.DNX.Helpers/Validation/GuardBuiltInTypesTests-Old.cs delete mode 100644 packages/repositories.config diff --git a/Test.DNX.Helpers/MultipleOutputHelper1.cs b/Test.DNX.Helpers/MultipleOutputHelper1.cs deleted file mode 100644 index 5f28270..0000000 --- a/Test.DNX.Helpers/MultipleOutputHelper1.cs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Test.DNX.Helpers/Properties/AssemblyInfo.cs b/Test.DNX.Helpers/Properties/AssemblyInfo.cs deleted file mode 100644 index 58d1e2f..0000000 --- a/Test.DNX.Helpers/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Test.DNX.Helpers")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("DNX Solutions Ltd")] -[assembly: AssemblyProduct("Test.DNX.Helpers")] -[assembly: AssemblyCopyright("Copyright © 2016 DNX Solutions Ltd")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("82d96365-52ad-4e50-9bb1-36295735ce64")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.2")] -[assembly: AssemblyFileVersion("1.2.2.0")] -[assembly: AssemblyInformationalVersion("1.2.2.0")] diff --git a/Test.DNX.Helpers/Test.DNX.Helpers.rctob b/Test.DNX.Helpers/Test.DNX.Helpers.rctob deleted file mode 100644 index 8bd0ff4..0000000 --- a/Test.DNX.Helpers/Test.DNX.Helpers.rctob +++ /dev/null @@ -1,2 +0,0 @@ -C:\Users\martin.smith\Dev\github\martinsmith1968\DNX.Helpers\DNX.Helpers.sln -Debug \ No newline at end of file diff --git a/Test.DNX.Helpers/Validation/GuardBuiltInTypesTests-Old.cs b/Test.DNX.Helpers/Validation/GuardBuiltInTypesTests-Old.cs deleted file mode 100644 index 133d953..0000000 --- a/Test.DNX.Helpers/Validation/GuardBuiltInTypesTests-Old.cs +++ /dev/null @@ -1,227 +0,0 @@ -using DNX.Helpers.Validation; -using NUnit.Framework; -using System; -using DNX.Helpers.Maths; - -namespace Test.DNX.Helpers.Validation -{ -#if TODO - [TestFixture] - public class GuardBuiltInTypesTests - { - [TestCase(150, 100, 200, ExpectedResult = true)] - [TestCase(101, 100, 200, ExpectedResult = true)] - [TestCase(199, 100, 200, ExpectedResult = true)] - [TestCase(100, 100, 200, ExpectedResult = true)] - [TestCase(200, 100, 200, ExpectedResult = true)] - [TestCase(-150, -100, -200, ExpectedResult = false)] - [TestCase(-150, -200, -100, ExpectedResult = true)] - [TestCase(-101, -200, -100, ExpectedResult = true)] - [TestCase(-199, -200, -100, ExpectedResult = true)] - [TestCase(-100, -200, -100, ExpectedResult = true)] - [TestCase(-200, -200, -100, ExpectedResult = true)] - [TestCase(50, 100, 200, ExpectedResult = false)] - [TestCase(250, 100, 200, ExpectedResult = false)] - [TestCase(100, 100, 200, ExpectedResult = true)] - [TestCase(200, 100, 200, ExpectedResult = true)] - [TestCase(100, 100, 100, ExpectedResult = true)] - public bool IsBetween_InclusiveDefault(int number, int min, int max) - { - try - { - // Act - Guard.IsBetween(() => number, min, max); - - return true; - } - catch (ArgumentOutOfRangeException) - { - return false; - } - catch (Exception ex) - { - // Assert - Assert.Fail(ex.Message); - return false; - } - } - - [TestCase(150, 100, 200, ExpectedResult = true)] - [TestCase(101, 100, 200, ExpectedResult = true)] - [TestCase(199, 100, 200, ExpectedResult = true)] - [TestCase(100, 100, 200, ExpectedResult = false)] - [TestCase(200, 100, 200, ExpectedResult = false)] - [TestCase(-150, -100, -200, ExpectedResult = false)] - [TestCase(-150, -200, -100, ExpectedResult = true)] - [TestCase(-101, -200, -100, ExpectedResult = true)] - [TestCase(-199, -200, -100, ExpectedResult = true)] - [TestCase(-100, -200, -100, ExpectedResult = false)] - [TestCase(-200, -200, -100, ExpectedResult = false)] - [TestCase(50, 100, 200, ExpectedResult = false)] - [TestCase(250, 100, 200, ExpectedResult = false)] - [TestCase(100, 100, 200, ExpectedResult = false)] - [TestCase(200, 100, 200, ExpectedResult = false)] - [TestCase(100, 100, 100, ExpectedResult = false)] - public bool IsBetween_NotInclusive(int number, int min, int max) - { - try - { - // Act - Guard.IsBetween(() => number, min, max, IsBetweenBoundsType.Exclusive); - - return true; - } - catch (ArgumentOutOfRangeException) - { - return false; - } - catch (Exception ex) - { - // Assert - Assert.Fail(ex.Message); - return false; - } - } - - [TestCase(150, 100, 200, ExpectedResult = true)] - [TestCase(101, 100, 200, ExpectedResult = true)] - [TestCase(199, 100, 200, ExpectedResult = true)] - [TestCase(100, 100, 200, ExpectedResult = true)] - [TestCase(200, 100, 200, ExpectedResult = true)] - [TestCase(150, 200, 100, ExpectedResult = true)] - [TestCase(101, 200, 100, ExpectedResult = true)] - [TestCase(199, 200, 100, ExpectedResult = true)] - [TestCase(100, 200, 100, ExpectedResult = true)] - [TestCase(200, 200, 100, ExpectedResult = true)] - [TestCase(-150, -100, -200, ExpectedResult = true)] - [TestCase(-150, -200, -100, ExpectedResult = true)] - [TestCase(-101, -200, -100, ExpectedResult = true)] - [TestCase(-199, -200, -100, ExpectedResult = true)] - [TestCase(-100, -200, -100, ExpectedResult = true)] - [TestCase(-200, -200, -100, ExpectedResult = true)] - [TestCase(-150, -200, -100, ExpectedResult = true)] - [TestCase(-150, -100, -200, ExpectedResult = true)] - [TestCase(-101, -100, -200, ExpectedResult = true)] - [TestCase(-199, -100, -200, ExpectedResult = true)] - [TestCase(-100, -100, -200, ExpectedResult = true)] - [TestCase(-200, -100, -200, ExpectedResult = true)] - [TestCase(50, 100, 200, ExpectedResult = false)] - [TestCase(250, 100, 200, ExpectedResult = false)] - [TestCase(50, 200, 100, ExpectedResult = false)] - [TestCase(250, 200, 100, ExpectedResult = false)] - [TestCase(100, 100, 200, ExpectedResult = true)] - [TestCase(200, 100, 200, ExpectedResult = true)] - [TestCase(100, 200, 100, ExpectedResult = true)] - [TestCase(200, 200, 100, ExpectedResult = true)] - [TestCase(100, 100, 100, ExpectedResult = true)] - public bool IsBetweenEither_InclusiveDefault(int number, int min, int max) - { - try - { - // Act - //Guard.IsBetweenEither(() => number, min, max); - - return true; - } - catch (ArgumentOutOfRangeException) - { - return false; - } - catch (Exception ex) - { - // Assert - Assert.Fail(ex.Message); - return false; - } - } - - [TestCase(150, 100, 200, ExpectedResult = true)] - [TestCase(101, 100, 200, ExpectedResult = true)] - [TestCase(199, 100, 200, ExpectedResult = true)] - [TestCase(100, 100, 200, ExpectedResult = false)] - [TestCase(200, 100, 200, ExpectedResult = false)] - [TestCase(150, 200, 100, ExpectedResult = true)] - [TestCase(101, 200, 100, ExpectedResult = true)] - [TestCase(199, 200, 100, ExpectedResult = true)] - [TestCase(100, 200, 100, ExpectedResult = false)] - [TestCase(200, 200, 100, ExpectedResult = false)] - [TestCase(-150, -100, -200, ExpectedResult = true)] - [TestCase(-150, -200, -100, ExpectedResult = true)] - [TestCase(-101, -200, -100, ExpectedResult = true)] - [TestCase(-199, -200, -100, ExpectedResult = true)] - [TestCase(-100, -200, -100, ExpectedResult = false)] - [TestCase(-200, -200, -100, ExpectedResult = false)] - [TestCase(-150, -200, -100, ExpectedResult = true)] - [TestCase(-150, -100, -200, ExpectedResult = true)] - [TestCase(-101, -100, -200, ExpectedResult = true)] - [TestCase(-199, -100, -200, ExpectedResult = true)] - [TestCase(-100, -100, -200, ExpectedResult = false)] - [TestCase(-200, -100, -200, ExpectedResult = false)] - [TestCase(50, 100, 200, ExpectedResult = false)] - [TestCase(250, 100, 200, ExpectedResult = false)] - [TestCase(50, 200, 100, ExpectedResult = false)] - [TestCase(250, 200, 100, ExpectedResult = false)] - [TestCase(100, 100, 200, ExpectedResult = false)] - [TestCase(200, 100, 200, ExpectedResult = false)] - [TestCase(100, 200, 100, ExpectedResult = false)] - [TestCase(200, 200, 100, ExpectedResult = false)] - [TestCase(100, 100, 100, ExpectedResult = false)] - public bool IsBetweenEither_NotInclusive(int number, int min, int max) - { - try - { - // Act - //Guard.IsBetweenEither(() => number, min, max, false); - - return true; - } - catch (ArgumentOutOfRangeException) - { - return false; - } - catch (Exception ex) - { - // Assert - Assert.Fail(ex.Message); - return false; - } - } - - [Test] - public void IsNotNullTest() - { - Assert.Fail(); - } - - [Test] - public void IsNotNullTest1() - { - Assert.Fail(); - } - - [Test] - public void IsNotNullOrEmptyTest() - { - Assert.Fail(); - } - - [Test] - public void IsNotNullOrEmptyTest1() - { - Assert.Fail(); - } - - [Test] - public void IsNotNullOrWhitespaceTest() - { - Assert.Fail(); - } - - [Test] - public void IsNotNullOrWhitespaceTest1() - { - Assert.Fail(); - } -#endif -} -} diff --git a/packages/repositories.config b/packages/repositories.config deleted file mode 100644 index 9f06f6c..0000000 --- a/packages/repositories.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From 4a17cf1f0ef089e6bb3ddabb027143abff703f23 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 20:14:59 +0000 Subject: [PATCH 07/14] Refactored for NETStandard --- DNX.Helpers/Strings/StringExtensions.cs | 64 ++++++++------- .../Strings/StringExtensionsTests.cs | 77 ++++++++++++++++++- 2 files changed, 112 insertions(+), 29 deletions(-) diff --git a/DNX.Helpers/Strings/StringExtensions.cs b/DNX.Helpers/Strings/StringExtensions.cs index a0f2d69..d97a02a 100644 --- a/DNX.Helpers/Strings/StringExtensions.cs +++ b/DNX.Helpers/Strings/StringExtensions.cs @@ -10,6 +10,15 @@ // ReSharper disable LoopCanBeConvertedToQuery namespace DNX.Helpers.Strings { + /// + /// How the delimiter is to be treated when splitting text + /// + public enum SplitDelimiterType + { + Any = 0, + All + } + /// /// String Extensions /// @@ -234,27 +243,14 @@ public static string RemoveStartsAndEndsWith(this string text, string prefix, st /// The text. /// The start text. /// The end text. + /// The comparison. /// System.String. - public static string Between(this string text, string startText, string endText) + public static string Between(this string text, string startText, string endText, StringComparison comparison = StringComparison.Ordinal) { - if (string.IsNullOrEmpty(text)) - { - return null; - } - - var startIndex = string.IsNullOrEmpty(startText) - ? -1 - : text.IndexOf(startText) + startText.Length; - - var endIndex = string.IsNullOrEmpty(endText) - ? -1 - : text.IndexOf(endText); - - var result = startIndex >= 0 && endIndex >= 0 && endIndex > startIndex - ? text.Substring(startIndex, endIndex - startIndex) - : null; - - return result; + return text + .After(startText, comparison) + .Before(endText, comparison) + ; } /// @@ -262,8 +258,9 @@ public static string Between(this string text, string startText, string endText) /// /// The text. /// The end text. + /// The comparison. /// System.String. - public static string Before(this string text, string endText) + public static string Before(this string text, string endText, StringComparison comparison = StringComparison.Ordinal) { if (text.IsNullOrEmpty()) { @@ -272,7 +269,7 @@ public static string Before(this string text, string endText) var endIndex = endText.IsNullOrEmpty() ? -1 - : text.IndexOf(endText); + : text.IndexOf(endText, comparison); var result = endIndex >= 0 ? text.Substring(0, endIndex) @@ -286,21 +283,23 @@ public static string Before(this string text, string endText) /// /// The text. /// The start text. + /// The comparison. /// System.String. - public static string After(this string text, string startText) + public static string After(this string text, string startText, StringComparison comparison = StringComparison.Ordinal) { if (string.IsNullOrEmpty(text)) { return null; } + var startTextLength = startText?.Length ?? 0; + var startIndex = string.IsNullOrEmpty(startText) ? -1 - : text.IndexOf(startText) + startText.Length; - + : text.IndexOf(startText, comparison); var result = startIndex >= 0 - ? text.Substring(startIndex) + ? text.Substring(startIndex + startTextLength) : null; return result; @@ -466,9 +465,20 @@ public static string Reverse(this string text) /// The options. /// IEnumerable<System.String>. /// Also available as an extension method - public static IEnumerable Split(this string text, string delimiters, StringSplitOptions options = StringSplitOptions.None) + public static IEnumerable SplitText(this string text, string delimiters, StringSplitOptions options = StringSplitOptions.None, SplitDelimiterType delimiterType = SplitDelimiterType.Any) { - return text.Split(delimiters.ToCharArray(), options); + switch (delimiterType) + { + case SplitDelimiterType.Any: + return text.Split(delimiters.ToCharArray(), options); + + case SplitDelimiterType.All: + // NOTE: A native text.Split(string, ...) is available in NET Core 2.1+ + return text.SplitByText(delimiters, options); + + default: + throw new ArgumentOutOfRangeException(nameof(delimiterType), delimiterType, $"Value must be one of {string.Join(",", Enum.GetNames(typeof(SplitDelimiterType)))}"); + } } /// diff --git a/Test.DNX.Helpers/Strings/StringExtensionsTests.cs b/Test.DNX.Helpers/Strings/StringExtensionsTests.cs index 709ccc9..c6a0bfe 100644 --- a/Test.DNX.Helpers/Strings/StringExtensionsTests.cs +++ b/Test.DNX.Helpers/Strings/StringExtensionsTests.cs @@ -3,6 +3,7 @@ using System.Globalization; using DNX.Helpers.Strings; using NUnit.Framework; +using Shouldly; namespace Test.DNX.Helpers.Strings { @@ -197,6 +198,8 @@ public string Test_RemoveStartsAndEndsWith_prefix_and_suffix(string text, string [TestCase("[Section Name]", null, "]", ExpectedResult = null)] [TestCase("[Section Name]", "[", null, ExpectedResult = null)] [TestCase("[Section Name]", null, null, ExpectedResult = null)] + [TestCase("A123B", "A", "B", ExpectedResult = "123")] + [TestCase("[Section Name]", "(", ")", ExpectedResult = null)] [TestCase("", "[", "]", ExpectedResult = null)] [TestCase(null, "[", "]", ExpectedResult = null)] public string Test_Between(string text, string startText, string endText) @@ -206,7 +209,19 @@ public string Test_Between(string text, string startText, string endText) return result; } + [TestCase("[Section Name]", "[", "]", StringComparison.CurrentCulture, ExpectedResult = "Section Name")] + [TestCase("[Section Name]", "(", ")", StringComparison.CurrentCulture, ExpectedResult = null)] + [TestCase("A123B", "a", "b", StringComparison.OrdinalIgnoreCase, ExpectedResult = "123")] + [TestCase("A123B", "a", "b", StringComparison.Ordinal, ExpectedResult = null)] + public string Test_Between_ComparisonType(string text, string startText, string endText, StringComparison comparison) + { + var result = text.Between(startText, endText, comparison); + + return result; + } + [TestCase("This is some text", "some", ExpectedResult = "This is ")] + [TestCase("This is some text", "bob", ExpectedResult = null)] [TestCase("This is some [[Red]]text[[/Red]]", "[[", ExpectedResult = "This is some ")] [TestCase("This is some text", " ", ExpectedResult = "This")] [TestCase("This is some text", "", ExpectedResult = null)] @@ -219,7 +234,19 @@ public string Test_Before(string text, string endText) return result; } + [TestCase("This is some text", "some", StringComparison.CurrentCulture, ExpectedResult = "This is ")] + [TestCase("This is some text", "bob", StringComparison.CurrentCulture, ExpectedResult = null)] + [TestCase("This is some text", "SOME", StringComparison.Ordinal, ExpectedResult = null)] + [TestCase("This is some text", "SOME", StringComparison.OrdinalIgnoreCase, ExpectedResult = "This is ")] + public string Test_Before_ComparisonType(string text, string endText, StringComparison comparison) + { + var result = text.Before(endText, comparison); + + return result; + } + [TestCase("This is some text", "some", ExpectedResult = " text")] + [TestCase("This is some text", "bob", ExpectedResult = null)] [TestCase("This is some [[Red]]text[[/Red]]", "[[", ExpectedResult = "Red]]text[[/Red]]")] [TestCase("This is some text", " ", ExpectedResult = "is some text")] [TestCase("This is some text", "", ExpectedResult = null)] @@ -232,6 +259,17 @@ public string Test_After(string text, string startText) return result; } + [TestCase("This is some text", "some", StringComparison.CurrentCulture, ExpectedResult = " text")] + [TestCase("This is some text", "bob", StringComparison.CurrentCulture, ExpectedResult = null)] + [TestCase("This is some text", "SOME", StringComparison.Ordinal, ExpectedResult = null)] + [TestCase("This is some text", "SOME", StringComparison.OrdinalIgnoreCase, ExpectedResult = " text")] + public string Test_After_ComparisonType(string text, string startText, StringComparison comparison) + { + var result = text.After(startText, comparison); + + return result; + } + [TestCase("bob", "b", StringComparison.CurrentCultureIgnoreCase, ExpectedResult = true)] [TestCase("BOB", "o", StringComparison.CurrentCultureIgnoreCase, ExpectedResult = true)] [TestCase("bob", "b", StringComparison.CurrentCulture, ExpectedResult = true)] @@ -389,13 +427,48 @@ public string Test_Reverse(string text) [TestCase("a-b--d-e", "-", StringSplitOptions.RemoveEmptyEntries, ExpectedResult = "a,b,d,e")] [TestCase("a-b[]d=e", "-[]=", StringSplitOptions.RemoveEmptyEntries, ExpectedResult = "a,b,d,e")] [TestCase("a-b[]d=e", "-[]=", StringSplitOptions.None, ExpectedResult = "a,b,,d,e")] - public string Test_Split(string text, string delimiters, StringSplitOptions options) + public string Test_SplitText(string text, string delimiters, StringSplitOptions options) + { + var result = text.SplitText(delimiters, options); + + return string.Join(",", result); + } + + [TestCase("a-b-c-d-e", "-", StringSplitOptions.None, SplitDelimiterType.Any, ExpectedResult = "a,b,c,d,e")] + [TestCase("a-b[c]d=e", "-[]=", StringSplitOptions.None, SplitDelimiterType.Any, ExpectedResult = "a,b,c,d,e")] + [TestCase("a-b--d-e", "-", StringSplitOptions.RemoveEmptyEntries, SplitDelimiterType.Any, ExpectedResult = "a,b,d,e")] + [TestCase("a-b[]d=e", "-[]=", StringSplitOptions.RemoveEmptyEntries, SplitDelimiterType.Any, ExpectedResult = "a,b,d,e")] + [TestCase("a-b[]d=e", "-[]=", StringSplitOptions.None, SplitDelimiterType.Any, ExpectedResult = "a,b,,d,e")] + [TestCase("a-b-c-d-e", "-", StringSplitOptions.None, SplitDelimiterType.All, ExpectedResult = "a,b,c,d,e")] + [TestCase("a-b--d-e", "--", StringSplitOptions.RemoveEmptyEntries, SplitDelimiterType.All, ExpectedResult = "a-b,d-e")] + [TestCase("a-b----d-e", "--", StringSplitOptions.None, SplitDelimiterType.All, ExpectedResult = "a-b,,d-e")] + [TestCase("a-b[]d=e", "[]", StringSplitOptions.RemoveEmptyEntries, SplitDelimiterType.All, ExpectedResult = "a-b,d=e")] + public string Test_SplitText_DelimiterType(string text, string delimiters, StringSplitOptions options, SplitDelimiterType delimiterType) { - var result = text.Split(delimiters, options); + var result = text.SplitText(delimiters, options, delimiterType); return string.Join(",", result); } + [Test] + public void Test_SplitText_InvalidDelimiterType() + { + // Arrange + var text = "a,b,c"; + var delimiters = ","; + + // Act + var ex = Assert.Throws( + () => text.SplitText(delimiters, StringSplitOptions.None, (SplitDelimiterType) int.MaxValue) + ); + + // Assert + ex.ShouldNotBeNull(); + ex.ParamName.ShouldBe("delimiterType"); + ex.Message.ShouldContain(nameof(SplitDelimiterType.Any)); + ex.Message.ShouldContain(nameof(SplitDelimiterType.All)); + } + [TestCase("a-b-c-d-e", "-", StringSplitOptions.None, ExpectedResult = "a,b,c,d,e")] [TestCase("a-b[c]d-e", "-", StringSplitOptions.None, ExpectedResult = "a,b[c]d,e")] [TestCase("a-b--d-e", "-", StringSplitOptions.RemoveEmptyEntries, ExpectedResult = "a,b,d,e")] From 089cb238f7eb233c35608a0c68a775f22b94cac9 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 20:15:11 +0000 Subject: [PATCH 08/14] Refactored for name clash with NETstandard --- DNX.Helpers/Linq/LinqExtensions.cs | 8 ++++---- Test.DNX.Helpers/Linq/LinqExtensionsTests.cs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DNX.Helpers/Linq/LinqExtensions.cs b/DNX.Helpers/Linq/LinqExtensions.cs index 8fa4373..fd70b51 100644 --- a/DNX.Helpers/Linq/LinqExtensions.cs +++ b/DNX.Helpers/Linq/LinqExtensions.cs @@ -103,17 +103,17 @@ public static bool IsNotIn(this T value, IList list, IEqualityComparer } /// - /// Appends the specified instance. + /// Appends the specified item instance. /// /// /// The enumerable. /// The instance. /// IEnumerable<T>. - public static IEnumerable Append(this IEnumerable enumerable, T instance) + public static IEnumerable AppendItem(this IEnumerable enumerable, T instance) { var falseComparer = EqualityComparerFunc.Create((arg1, arg2) => false); - return enumerable.Append(instance, falseComparer); + return enumerable.AppendItem(instance, falseComparer); } /// @@ -124,7 +124,7 @@ public static IEnumerable Append(this IEnumerable enumerable, T instanc /// The instance. /// The comparer. /// IEnumerable<T>. - public static IEnumerable Append(this IEnumerable enumerable, T instance, IEqualityComparer comparer) + public static IEnumerable AppendItem(this IEnumerable enumerable, T instance, IEqualityComparer comparer) { return (enumerable ?? Enumerable.Empty()) .Union(new[] { instance }, comparer); diff --git a/Test.DNX.Helpers/Linq/LinqExtensionsTests.cs b/Test.DNX.Helpers/Linq/LinqExtensionsTests.cs index bbd5c6f..7e43b9c 100644 --- a/Test.DNX.Helpers/Linq/LinqExtensionsTests.cs +++ b/Test.DNX.Helpers/Linq/LinqExtensionsTests.cs @@ -165,13 +165,13 @@ public void Test_IsNotIn_Params() [TestCase("a,b,c", "a", ExpectedResult = "a,b,c,a")] [TestCase(null, "a", ExpectedResult = "a")] [TestCase("", "a", ExpectedResult = "a")] - public string Test_Append(string commaDelimitedArray, string value) + public string Test_AppendItem(string commaDelimitedArray, string value) { var enumerable = commaDelimitedArray == null ? null : commaDelimitedArray.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); - var result = enumerable.Append(value); + var result = enumerable.AppendItem(value); return string.Join(",", result); } @@ -191,7 +191,7 @@ public string Test_Append_CaseInsensitiveComparer(string commaDelimitedArray, st ? null : commaDelimitedArray.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); - var result = enumerable.Append(value, comparer); + var result = enumerable.AppendItem(value, comparer); return string.Join(",", result); } From 26decb1b59bbc699f0e810050ba5b98cd4646ab6 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 20:15:24 +0000 Subject: [PATCH 09/14] New csproj --- Test.DNX.Helpers/Test.DNX.Helpers.csproj | 484 +++-------------------- 1 file changed, 45 insertions(+), 439 deletions(-) diff --git a/Test.DNX.Helpers/Test.DNX.Helpers.csproj b/Test.DNX.Helpers/Test.DNX.Helpers.csproj index 37fb2ed..123b737 100644 --- a/Test.DNX.Helpers/Test.DNX.Helpers.csproj +++ b/Test.DNX.Helpers/Test.DNX.Helpers.csproj @@ -1,455 +1,61 @@ - - - + - Debug - AnyCPU - {B3666B7C-ADF3-46B1-8955-D3224F4A9C8D} - Library - Properties - Test.DNX.Helpers - Test.DNX.Helpers - v4.5.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - ..\ - true - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + netcoreapp2.1 + 2.0.0 + Martin Smith + Tests for DNX.Helpers + Copyright © 2016-2019 DNX Solutions Ltd + licence.txt + https://github.com/martinsmith1968/DNX.Helpers + favicon-32x32.png + - - ..\packages\Bogus.28.4.4\lib\net40\Bogus.dll - - - ..\packages\NBuilder.6.1.0\lib\net40\FizzWare.NBuilder.dll - - - - ..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll - - - ..\packages\Shouldly.3.0.2\lib\net451\Shouldly.dll - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - True - True - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - ConvertExtensionsTemplate.tt - - - - - - - - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - True - True - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - True - True - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - MathsExtensionsTestsSourceTemplate.tt - - - - MultipleOutputHelper.ttinclude - True - True - - - - - - - - - - - - - - - True - True - GuardTestsSourceTemplate.tt - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - - TextTemplatingFileGenerator - MathsExtensionsTestsSourceTemplate.cs - - - TextTemplatingFileGenerator - GuardBuiltInTypesTests.cs - True - True - True - - - True - True - GuardBuiltInTypesTests.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardTestsSourceTemplate.tt - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - GuardBuiltInTypesTests.tt - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {BC278532-83D1-4AC0-BA01-E16F237BCBF9} - DNX.Helpers - + - - TextTemplatingFileGenerator - MultipleOutputHelper1.cs + + True + + + + True + - - + TextTemplatingFileGenerator - ConvertExtensionsTemplate.cs - True - True - True - - - TextTemplatingFileGenerator - MathsExtensionsTestsTemplate.cs - True - True - True - - + GuardBuiltInTypesTests.cs + + TextTemplatingFileGenerator GuardTestsSourceTemplate.cs - True - True - + + + + - + + True + True + GuardBuiltInTypesTests.tt + + + True + True + GuardTestsSourceTemplate.tt + - - - - - - False - - - False - - - False - - - False - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file + From 85f1524363a5c14617c468d4cb010153f05eac39 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 20:15:40 +0000 Subject: [PATCH 10/14] Altered tests for assembly info now in csproj --- Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs b/Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs index 36841fa..460b883 100644 --- a/Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs +++ b/Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs @@ -30,7 +30,7 @@ public void AssemblyDetails_created_from_current_assembly() assemblyDetails.Copyright.ShouldBe(targetAssembly.GetCustomAttributes().First().Copyright); assemblyDetails.Company.ShouldBe(targetAssembly.GetCustomAttributes().First().Company); assemblyDetails.Description.ShouldBe(targetAssembly.GetCustomAttributes().First().Description); - assemblyDetails.Trademark.ShouldBe(targetAssembly.GetCustomAttributes().First().Trademark); + assemblyDetails.Trademark.ShouldBe(targetAssembly.GetCustomAttributes().FirstOrDefault()?.Trademark); assemblyDetails.Configuration.ShouldBe(targetAssembly.GetCustomAttributes().First().Configuration); assemblyDetails.Version.ShouldBe(targetAssembly.GetName().Version); assemblyDetails.FileVersion.ShouldBe(targetAssembly.GetCustomAttributes().First().Version); @@ -59,11 +59,11 @@ public void AssemblyDetails_created_from_specific_assembly() assemblyDetails.Copyright.ShouldBe(targetAssembly.GetCustomAttributes().First().Copyright); assemblyDetails.Company.ShouldBe(targetAssembly.GetCustomAttributes().First().Company); assemblyDetails.Description.ShouldBe(targetAssembly.GetCustomAttributes().First().Description); - assemblyDetails.Trademark.ShouldBe(targetAssembly.GetCustomAttributes().First().Trademark); + assemblyDetails.Trademark.ShouldBe(targetAssembly.GetCustomAttributes().FirstOrDefault()?.Trademark); assemblyDetails.Configuration.ShouldBe(targetAssembly.GetCustomAttributes().First().Configuration); assemblyDetails.Version.ShouldBe(targetAssembly.GetName().Version); assemblyDetails.FileVersion.ShouldBe(targetAssembly.GetCustomAttributes().First().Version); - assemblyDetails.InformationalVersion.ShouldBeNull(); + assemblyDetails.InformationalVersion.ShouldBe(targetAssembly.GetCustomAttributes().First().InformationalVersion); assemblyDetails.SimplifiedVersion.ShouldBe(assemblyDetails.Version.Simplify()); } } From d0d19e7f48e7da8318d4c637dbb12f5c14090640 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 20:16:03 +0000 Subject: [PATCH 11/14] Reworked travisCI yaml for net core builds --- .travis.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index abe7e47..346f521 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ env: NUNIT_RUNNERS_VERSION=3.10.0 language: csharp +mono: none +dotnet: 2.1.502 solution: $APPNAME.sln @@ -16,16 +18,20 @@ install: - nuget install NUnit.Runners -Version $NUNIT_RUNNERS_VERSION -OutputDirectory testrunner script: + - dotnet restore + - dotnet build -c $CONFIGURATION + - dotnet test -v normal + - dotnet pack -c $CONFIGURATION # - xbuild /p:Configuration=$CONFIGURATION $APPNAME.sln - - msbuild /p:Configuration=$CONFIGURATION $APPNAME.sln - - mono ./testrunner/NUnit.ConsoleRunner.$NUNIT_RUNNERS_VERSION/tools/nunit3-console.exe ./Test.$APPNAME/bin/$CONFIGURATION/Test.$APPNAME.dll + # - msbuild /p:Configuration=$CONFIGURATION $APPNAME.sln + # - mono ./testrunner/NUnit.ConsoleRunner.$NUNIT_RUNNERS_VERSION/tools/nunit3-console.exe ./Test.$APPNAME/bin/$CONFIGURATION/Test.$APPNAME.dll - ls -laR ./$APPNAME # https://stackoverflow.com/questions/14797525/differences-between-nuget-packing-a-csproj-vs-nuspec - - nuget pack ./$APPNAME/$APPNAME.csproj -Verbosity detailed + # - nuget pack ./$APPNAME/$APPNAME.csproj -Verbosity detailed deploy: skip_cleanup: true provider: script - script: nuget push $APPNAME.*.nupkg -Source $NUGET_API_URL -ApiKey $NUGET_API_KEY + script: nuget push $APPNAME/bin/$CONFIGURATION/$APPNAME.*.nupkg -Source $NUGET_API_URL -ApiKey $NUGET_API_KEY on: branch: master From afbe2bd393b267bba6a41898400373a158efc247 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 20:19:20 +0000 Subject: [PATCH 12/14] Remove pre-install script as nuget command not available --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 346f521..2d57381 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,9 @@ dotnet: 2.1.502 solution: $APPNAME.sln -install: - - nuget restore $APPNAME.sln - - nuget install NUnit.Runners -Version $NUNIT_RUNNERS_VERSION -OutputDirectory testrunner +# install: +# - nuget restore $APPNAME.sln +# - nuget install NUnit.Runners -Version $NUNIT_RUNNERS_VERSION -OutputDirectory testrunner script: - dotnet restore From a2a478abd326120d770c3a37e06367136fb1d979 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 22:09:17 +0000 Subject: [PATCH 13/14] Use latest dotnet --- .travis.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2d57381..f6fe150 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,25 +9,18 @@ env: language: csharp mono: none -dotnet: 2.1.502 +dotnet: latest solution: $APPNAME.sln -# install: -# - nuget restore $APPNAME.sln -# - nuget install NUnit.Runners -Version $NUNIT_RUNNERS_VERSION -OutputDirectory testrunner +install: + - dotnet restore script: - - dotnet restore - dotnet build -c $CONFIGURATION - dotnet test -v normal - dotnet pack -c $CONFIGURATION - # - xbuild /p:Configuration=$CONFIGURATION $APPNAME.sln - # - msbuild /p:Configuration=$CONFIGURATION $APPNAME.sln - # - mono ./testrunner/NUnit.ConsoleRunner.$NUNIT_RUNNERS_VERSION/tools/nunit3-console.exe ./Test.$APPNAME/bin/$CONFIGURATION/Test.$APPNAME.dll - - ls -laR ./$APPNAME - # https://stackoverflow.com/questions/14797525/differences-between-nuget-packing-a-csproj-vs-nuspec - # - nuget pack ./$APPNAME/$APPNAME.csproj -Verbosity detailed + # - ls -laR ./$APPNAME deploy: skip_cleanup: true From bcfca307818c7810ebb0683758d9dc84b8674723 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sat, 28 Dec 2019 22:17:14 +0000 Subject: [PATCH 14/14] Fix dotnet version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f6fe150..9f5ca9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ env: language: csharp mono: none -dotnet: latest +dotnet: 2.2.102 solution: $APPNAME.sln