From 8601aa8950a7339f5d477073771a904cbe96c72e Mon Sep 17 00:00:00 2001 From: j0nimost Date: Fri, 13 May 2022 17:05:24 +0300 Subject: [PATCH 1/3] Added checkers for integers, floats and decimal --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index b20ef0f247..1dc5901704 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -162,4 +162,182 @@ public static class Check return value; } + + public static Int16 NotNegativeOrZero( + Int16 type, + [InvokerParameterName][NotNull] string parameterName) + { + if(type == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if(type < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return type; + } + + public static Int32 NotNegativeOrZero( + Int32 type, + [InvokerParameterName][NotNull] string parameterName) + { + if (type == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (type < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return type; + } + + public static Int64 NotNegativeOrZero( + Int64 type, + [InvokerParameterName][NotNull] string parameterName) + { + if (type == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (type < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return type; + } + + public static float NotNegativeOrZero( + float type, + [InvokerParameterName][NotNull] string parameterName) + { + if (type == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (type < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return type; + } + + public static double NotNegativeOrZero( + double type, + [InvokerParameterName][NotNull] string parameterName) + { + if (type == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (type < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return type; + } + + public static decimal NotNegativeOrZero( + decimal type, + [InvokerParameterName][NotNull] string parameterName) + { + if (type == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (type < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return type; + } + + + + public static Int16 WithinRange( + Int16 type, + [InvokerParameterName][NotNull] string parameterName, + Int16 minimumValue, + Int16 maximumValue = Int16.MaxValue) + { + if(type < minimumValue || type > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return type; + } + public static Int32 WithinRange( + Int32 type, + [InvokerParameterName][NotNull] string parameterName, + Int32 minimumValue, + Int32 maximumValue = Int32.MaxValue) + { + if (type < minimumValue || type > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return type; + } + + public static Int64 WithinRange( + Int64 type, + [InvokerParameterName][NotNull] string parameterName, + Int64 minimumValue, + Int64 maximumValue = Int64.MaxValue) + { + if (type < minimumValue || type > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return type; + } + + + public static float WithinRange( + float type, + [InvokerParameterName][NotNull] string parameterName, + float minimumValue, + float maximumValue = float.MaxValue) + { + if (type < minimumValue || type > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return type; + } + + public static double WithinRange( + double type, + [InvokerParameterName][NotNull] string parameterName, + double minimumValue, + double maximumValue = double.MaxValue) + { + if (type < minimumValue || type > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return type; + } + + + public static decimal WithinRange( + decimal type, + [InvokerParameterName][NotNull] string parameterName, + decimal minimumValue, + decimal maximumValue = decimal.MaxValue) + { + if (type < minimumValue || type > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return type; + } + } From aa08d0d5ad86e298e433c15c26a82a36f8a173b9 Mon Sep 17 00:00:00 2001 From: j0nimost Date: Mon, 16 May 2022 09:19:52 +0300 Subject: [PATCH 2/3] Renamed the method names --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index 1dc5901704..af8017059d 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -163,7 +163,7 @@ public static class Check return value; } - public static Int16 NotNegativeOrZero( + public static Int16 Positive( Int16 type, [InvokerParameterName][NotNull] string parameterName) { @@ -178,7 +178,7 @@ public static class Check return type; } - public static Int32 NotNegativeOrZero( + public static Int32 Positive( Int32 type, [InvokerParameterName][NotNull] string parameterName) { @@ -193,7 +193,7 @@ public static class Check return type; } - public static Int64 NotNegativeOrZero( + public static Int64 Positive( Int64 type, [InvokerParameterName][NotNull] string parameterName) { @@ -208,7 +208,7 @@ public static class Check return type; } - public static float NotNegativeOrZero( + public static float Positive( float type, [InvokerParameterName][NotNull] string parameterName) { @@ -223,7 +223,7 @@ public static class Check return type; } - public static double NotNegativeOrZero( + public static double Positive( double type, [InvokerParameterName][NotNull] string parameterName) { @@ -238,7 +238,7 @@ public static class Check return type; } - public static decimal NotNegativeOrZero( + public static decimal Positive( decimal type, [InvokerParameterName][NotNull] string parameterName) { @@ -255,7 +255,7 @@ public static class Check - public static Int16 WithinRange( + public static Int16 Range( Int16 type, [InvokerParameterName][NotNull] string parameterName, Int16 minimumValue, @@ -268,7 +268,7 @@ public static class Check return type; } - public static Int32 WithinRange( + public static Int32 Range( Int32 type, [InvokerParameterName][NotNull] string parameterName, Int32 minimumValue, @@ -282,7 +282,7 @@ public static class Check return type; } - public static Int64 WithinRange( + public static Int64 Range( Int64 type, [InvokerParameterName][NotNull] string parameterName, Int64 minimumValue, @@ -297,7 +297,7 @@ public static class Check } - public static float WithinRange( + public static float Range( float type, [InvokerParameterName][NotNull] string parameterName, float minimumValue, @@ -311,7 +311,7 @@ public static class Check return type; } - public static double WithinRange( + public static double Range( double type, [InvokerParameterName][NotNull] string parameterName, double minimumValue, @@ -326,7 +326,7 @@ public static class Check } - public static decimal WithinRange( + public static decimal Range( decimal type, [InvokerParameterName][NotNull] string parameterName, decimal minimumValue, From daab524943f7e6bad8259fa6a90ee833495236f1 Mon Sep 17 00:00:00 2001 From: j0nimost Date: Mon, 16 May 2022 09:23:04 +0300 Subject: [PATCH 3/3] Renamed the property name from type -> value --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index af8017059d..faab005376 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -164,180 +164,180 @@ public static class Check } public static Int16 Positive( - Int16 type, + Int16 value, [InvokerParameterName][NotNull] string parameterName) { - if(type == 0) + if(value == 0) { throw new ArgumentException($"{parameterName} is equal to zero"); } - else if(type < 0) + else if(value < 0) { throw new ArgumentException($"{parameterName} is less than zero"); } - return type; + return value; } public static Int32 Positive( - Int32 type, + Int32 value, [InvokerParameterName][NotNull] string parameterName) { - if (type == 0) + if (value == 0) { throw new ArgumentException($"{parameterName} is equal to zero"); } - else if (type < 0) + else if (value < 0) { throw new ArgumentException($"{parameterName} is less than zero"); } - return type; + return value; } public static Int64 Positive( - Int64 type, + Int64 value, [InvokerParameterName][NotNull] string parameterName) { - if (type == 0) + if (value == 0) { throw new ArgumentException($"{parameterName} is equal to zero"); } - else if (type < 0) + else if (value < 0) { throw new ArgumentException($"{parameterName} is less than zero"); } - return type; + return value; } public static float Positive( - float type, + float value, [InvokerParameterName][NotNull] string parameterName) { - if (type == 0) + if (value == 0) { throw new ArgumentException($"{parameterName} is equal to zero"); } - else if (type < 0) + else if (value < 0) { throw new ArgumentException($"{parameterName} is less than zero"); } - return type; + return value; } public static double Positive( - double type, + double value, [InvokerParameterName][NotNull] string parameterName) { - if (type == 0) + if (value == 0) { throw new ArgumentException($"{parameterName} is equal to zero"); } - else if (type < 0) + else if (value < 0) { throw new ArgumentException($"{parameterName} is less than zero"); } - return type; + return value; } public static decimal Positive( - decimal type, + decimal value, [InvokerParameterName][NotNull] string parameterName) { - if (type == 0) + if (value == 0) { throw new ArgumentException($"{parameterName} is equal to zero"); } - else if (type < 0) + else if (value < 0) { throw new ArgumentException($"{parameterName} is less than zero"); } - return type; + return value; } public static Int16 Range( - Int16 type, + Int16 value, [InvokerParameterName][NotNull] string parameterName, Int16 minimumValue, Int16 maximumValue = Int16.MaxValue) { - if(type < minimumValue || type > maximumValue) + if(value < minimumValue || value > maximumValue) { throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); } - return type; + return value; } public static Int32 Range( - Int32 type, + Int32 value, [InvokerParameterName][NotNull] string parameterName, Int32 minimumValue, Int32 maximumValue = Int32.MaxValue) { - if (type < minimumValue || type > maximumValue) + if (value < minimumValue || value > maximumValue) { throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); } - return type; + return value; } public static Int64 Range( - Int64 type, + Int64 value, [InvokerParameterName][NotNull] string parameterName, Int64 minimumValue, Int64 maximumValue = Int64.MaxValue) { - if (type < minimumValue || type > maximumValue) + if (value < minimumValue || value > maximumValue) { throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); } - return type; + return value; } public static float Range( - float type, + float value, [InvokerParameterName][NotNull] string parameterName, float minimumValue, float maximumValue = float.MaxValue) { - if (type < minimumValue || type > maximumValue) + if (value < minimumValue || value > maximumValue) { throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); } - return type; + return value; } public static double Range( - double type, + double value, [InvokerParameterName][NotNull] string parameterName, double minimumValue, double maximumValue = double.MaxValue) { - if (type < minimumValue || type > maximumValue) + if (value < minimumValue || value > maximumValue) { throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); } - return type; + return value; } public static decimal Range( - decimal type, + decimal value, [InvokerParameterName][NotNull] string parameterName, decimal minimumValue, decimal maximumValue = decimal.MaxValue) { - if (type < minimumValue || type > maximumValue) + if (value < minimumValue || value > maximumValue) { throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); } - return type; + return value; } }