From 8f498eb5905df308d6fefa99255ce1310c387c78 Mon Sep 17 00:00:00 2001 From: j0nimost Date: Mon, 16 May 2022 10:43:47 +0300 Subject: [PATCH 1/6] Added checker for Struct types --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 13 +++++++++++++ 1 file changed, 13 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..99c1148971 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -162,4 +162,17 @@ public static class Check return value; } + + public static T NotDefault( + T value, + [InvokerParameterName][NotNull] string parameterName) + where T : struct + { + if(value.Equals(default(T))) + { + throw new ArgumentException($"{parameterName} has a default value or is empty!", parameterName); + } + + return value; + } } From 643d045cc42296f90404d20f74cc836771a5c6ba Mon Sep 17 00:00:00 2001 From: j0nimost Date: Thu, 19 May 2022 15:39:28 +0300 Subject: [PATCH 2/6] fix merge error --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index d4361875ec..01ffc8c55b 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -163,18 +163,7 @@ public static class Check return value; } - public static T NotDefault( - T value, - [InvokerParameterName][NotNull] string parameterName) - where T : struct - { - if(value.Equals(default(T))) - { - throw new ArgumentException($"{parameterName} has a default value or is empty!", parameterName); - } - return value; - } public static Int16 Positive( Int16 value, @@ -319,6 +308,10 @@ public static class Check if (value < minimumValue || value > maximumValue) { throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + return value; + } + public static double Range( double value, @@ -349,4 +342,17 @@ public static class Check return value; } + public static T NotDefault( + T value, + [InvokerParameterName][NotNull] string parameterName) + where T : struct + { + if(value.Equals(default(T))) + { + throw new ArgumentException($"{parameterName} has a default value or is empty!", parameterName); + } + + return value; + } + } From a4bc569e155b1b65c92e6e74b6f26cbe33df336d Mon Sep 17 00:00:00 2001 From: j0nimost Date: Mon, 23 May 2022 10:39:53 +0300 Subject: [PATCH 3/6] Implemented a Null or Empty checker for structs --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index 01ffc8c55b..7758058e95 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -342,17 +342,28 @@ public static class Check return value; } - public static T NotDefault( - T value, - [InvokerParameterName][NotNull] string parameterName) + /// + /// Checks if value of type T (struct) is empty, default or null + /// + /// + /// + /// + /// + /// + public static T NotDefaultorNull( + Nullable value, + string parameterName) where T : struct - { - if(value.Equals(default(T))) + { + if (value.Equals(default(T))) { throw new ArgumentException($"{parameterName} has a default value or is empty!", parameterName); } - - return value; - } + else if (value.HasValue == false) + { + throw new ArgumentException($"{parameterName} is null!", parameterName); + } + return (T)value; + } } From d2a9d43ea46cc13fb5210b6f03f0c74a23a69a9e Mon Sep 17 00:00:00 2001 From: j0nimost Date: Mon, 23 May 2022 10:41:09 +0300 Subject: [PATCH 4/6] Added parameterName validation --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index 7758058e95..c31d616518 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -352,7 +352,7 @@ public static class Check /// public static T NotDefaultorNull( Nullable value, - string parameterName) + [InvokerParameterName][NotNull] string parameterName) where T : struct { if (value.Equals(default(T))) From 20950b576e8623bc81d7f8caf1dbe27d10fdf377 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 27 May 2022 08:34:23 +0800 Subject: [PATCH 5/6] Update Check.cs --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index c31d616518..8979c897a3 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -163,8 +163,6 @@ public static class Check return value; } - - public static Int16 Positive( Int16 value, [InvokerParameterName][NotNull] string parameterName) @@ -363,6 +361,7 @@ public static class Check { throw new ArgumentException($"{parameterName} is null!", parameterName); } + return (T)value; } From c3d9f94f7928b3a8e825821346e9ba2ac1ada4b0 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 27 May 2022 08:48:25 +0800 Subject: [PATCH 6/6] Update Check.cs --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index 8979c897a3..a2448190a5 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -253,8 +253,6 @@ public static class Check return value; } - - public static Int16 Range( Int16 value, [InvokerParameterName][NotNull] string parameterName, @@ -340,29 +338,21 @@ public static class Check return value; } - /// - /// Checks if value of type T (struct) is empty, default or null - /// - /// - /// - /// - /// - /// - public static T NotDefaultorNull( - Nullable value, + public static T NotDefaultOrNull( + T? value, [InvokerParameterName][NotNull] string parameterName) where T : struct { - if (value.Equals(default(T))) + if (value == null) { - throw new ArgumentException($"{parameterName} has a default value or is empty!", parameterName); + throw new ArgumentException($"{parameterName} is null!", parameterName); } - else if (value.HasValue == false) + + if (value.Value.Equals(default(T))) { - throw new ArgumentException($"{parameterName} is null!", parameterName); + throw new ArgumentException($"{parameterName} has a default value!", parameterName); } - return (T)value; + return value.Value; } - }