From a4bc569e155b1b65c92e6e74b6f26cbe33df336d Mon Sep 17 00:00:00 2001 From: j0nimost Date: Mon, 23 May 2022 10:39:53 +0300 Subject: [PATCH] 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; + } }