From 105e029244e87b6b2b6d6d44a2758428197cd9ac Mon Sep 17 00:00:00 2001 From: Rafael Gonzales Date: Fri, 11 Aug 2023 23:14:25 -0500 Subject: [PATCH] Accept nullable values in validation methods --- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index 4aa3c10ecb..0e6820c913 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -10,7 +10,7 @@ public static class Check { [ContractAnnotation("value:null => halt")] public static T NotNull( - T value, + T? value, [InvokerParameterName][NotNull] string parameterName) { if (value == null) @@ -23,7 +23,7 @@ public static class Check [ContractAnnotation("value:null => halt")] public static T NotNull( - T value, + T? value, [InvokerParameterName][NotNull] string parameterName, string message) { @@ -37,7 +37,7 @@ public static class Check [ContractAnnotation("value:null => halt")] public static string NotNull( - string value, + string? value, [InvokerParameterName][NotNull] string parameterName, int maxLength = int.MaxValue, int minLength = 0) @@ -77,7 +77,7 @@ public static class Check throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName); } - if (minLength > 0 && value.Length < minLength) + if (minLength > 0 && value!.Length < minLength) { throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName); } @@ -102,7 +102,7 @@ public static class Check throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName); } - if (minLength > 0 && value.Length < minLength) + if (minLength > 0 && value!.Length < minLength) { throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName); } @@ -111,9 +111,9 @@ public static class Check } [ContractAnnotation("value:null => halt")] - public static ICollection NotNullOrEmpty(ICollection value, [InvokerParameterName][NotNull] string parameterName) + public static ICollection NotNullOrEmpty(ICollection? value, [InvokerParameterName][NotNull] string parameterName) { - if (value.IsNullOrEmpty()) + if (value == null || value.Count <= 0) { throw new ArgumentException(parameterName + " can not be null or empty!", parameterName); } @@ -167,11 +167,11 @@ public static class Check Int16 value, [InvokerParameterName][NotNull] string parameterName) { - if(value == 0) + if (value == 0) { throw new ArgumentException($"{parameterName} is equal to zero"); } - else if(value < 0) + else if (value < 0) { throw new ArgumentException($"{parameterName} is less than zero"); } @@ -259,7 +259,7 @@ public static class Check Int16 minimumValue, Int16 maximumValue = Int16.MaxValue) { - if(value < minimumValue || value > maximumValue) + if (value < minimumValue || value > maximumValue) { throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); }