Browse Source
Merge pull request #12602 from j0nimost/feat/checkers-structs
Added checker for Struct types
pull/12792/head
maliming
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
18 additions and
3 deletions
-
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, |
|
|
|
@ -307,10 +305,10 @@ public static class Check |
|
|
|
{ |
|
|
|
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); |
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static double Range( |
|
|
|
double value, |
|
|
|
[InvokerParameterName][NotNull] string parameterName, |
|
|
|
@ -340,4 +338,21 @@ public static class Check |
|
|
|
return value; |
|
|
|
} |
|
|
|
|
|
|
|
public static T NotDefaultOrNull<T>( |
|
|
|
T? value, |
|
|
|
[InvokerParameterName][NotNull] string parameterName) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
if (value == null) |
|
|
|
{ |
|
|
|
throw new ArgumentException($"{parameterName} is null!", parameterName); |
|
|
|
} |
|
|
|
|
|
|
|
if (value.Value.Equals(default(T))) |
|
|
|
{ |
|
|
|
throw new ArgumentException($"{parameterName} has a default value!", parameterName); |
|
|
|
} |
|
|
|
|
|
|
|
return value.Value; |
|
|
|
} |
|
|
|
} |
|
|
|
|