|
|
@ -16,29 +16,33 @@ namespace Squidex.Infrastructure |
|
|
{ |
|
|
{ |
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void ValidNumber(float target, |
|
|
public static float ValidNumber(float target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
if (float.IsNaN(target) || float.IsPositiveInfinity(target) || float.IsNegativeInfinity(target)) |
|
|
if (float.IsNaN(target) || float.IsPositiveInfinity(target) || float.IsNegativeInfinity(target)) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Value must be a valid number.", parameterName); |
|
|
throw new ArgumentException("Value must be a valid number.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void ValidNumber(double target, |
|
|
public static double ValidNumber(double target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
if (double.IsNaN(target) || double.IsPositiveInfinity(target) || double.IsNegativeInfinity(target)) |
|
|
if (double.IsNaN(target) || double.IsPositiveInfinity(target) || double.IsNegativeInfinity(target)) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Value must be a valid number.", parameterName); |
|
|
throw new ArgumentException("Value must be a valid number.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void ValidSlug(string? target, |
|
|
public static string ValidSlug(string? target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
NotNullOrEmpty(target, parameterName); |
|
|
NotNullOrEmpty(target, parameterName); |
|
|
@ -47,11 +51,13 @@ namespace Squidex.Infrastructure |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Target is not a valid slug.", parameterName); |
|
|
throw new ArgumentException("Target is not a valid slug.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target!; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void ValidPropertyName(string? target, |
|
|
public static string ValidPropertyName(string? target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
NotNullOrEmpty(target, parameterName); |
|
|
NotNullOrEmpty(target, parameterName); |
|
|
@ -60,99 +66,117 @@ namespace Squidex.Infrastructure |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Target is not a valid property name.", parameterName); |
|
|
throw new ArgumentException("Target is not a valid property name.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target!; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void HasType<T>(object? target, |
|
|
public static object? HasType<T>(object? target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
if (target != null && target.GetType() != typeof(T)) |
|
|
if (target != null && target.GetType() != typeof(T)) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException($"The parameter must be of type {typeof(T)}", parameterName); |
|
|
throw new ArgumentException($"The parameter must be of type {typeof(T)}", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void HasType(object? target, Type? expectedType, |
|
|
public static object? HasType(object? target, Type? expectedType, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
if (target != null && expectedType != null && target.GetType() != expectedType) |
|
|
if (target != null && expectedType != null && target.GetType() != expectedType) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException($"The parameter must be of type {expectedType}", parameterName); |
|
|
throw new ArgumentException($"The parameter must be of type {expectedType}", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void Between<TValue>(TValue target, TValue lower, TValue upper, |
|
|
public static TValue Between<TValue>(TValue target, TValue lower, TValue upper, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
{ |
|
|
{ |
|
|
if (!target.IsBetween(lower, upper)) |
|
|
if (!target.IsBetween(lower, upper)) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException($"Value must be between {lower} and {upper}", parameterName); |
|
|
throw new ArgumentException($"Value must be between {lower} and {upper}", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void Enum<TEnum>(TEnum target, |
|
|
public static TEnum Enum<TEnum>(TEnum target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TEnum : struct |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TEnum : struct |
|
|
{ |
|
|
{ |
|
|
if (!target.IsEnumValue()) |
|
|
if (!target.IsEnumValue()) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException($"Value must be a valid enum type {typeof(TEnum)}", parameterName); |
|
|
throw new ArgumentException($"Value must be a valid enum type {typeof(TEnum)}", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void GreaterThan<TValue>(TValue target, TValue lower, |
|
|
public static TValue GreaterThan<TValue>(TValue target, TValue lower, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
{ |
|
|
{ |
|
|
if (target.CompareTo(lower) <= 0) |
|
|
if (target.CompareTo(lower) <= 0) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException($"Value must be greater than {lower}", parameterName); |
|
|
throw new ArgumentException($"Value must be greater than {lower}", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void GreaterEquals<TValue>(TValue target, TValue lower, |
|
|
public static TValue GreaterEquals<TValue>(TValue target, TValue lower, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
{ |
|
|
{ |
|
|
if (target.CompareTo(lower) < 0) |
|
|
if (target.CompareTo(lower) < 0) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException($"Value must be greater or equal to {lower}", parameterName); |
|
|
throw new ArgumentException($"Value must be greater or equal to {lower}", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void LessThan<TValue>(TValue target, TValue upper, |
|
|
public static TValue LessThan<TValue>(TValue target, TValue upper, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
{ |
|
|
{ |
|
|
if (target.CompareTo(upper) >= 0) |
|
|
if (target.CompareTo(upper) >= 0) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException($"Value must be less than {upper}", parameterName); |
|
|
throw new ArgumentException($"Value must be less than {upper}", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void LessEquals<TValue>(TValue target, TValue upper, |
|
|
public static TValue LessEquals<TValue>(TValue target, TValue upper, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : IComparable |
|
|
{ |
|
|
{ |
|
|
if (target.CompareTo(upper) > 0) |
|
|
if (target.CompareTo(upper) > 0) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException($"Value must be less or equal to {upper}", parameterName); |
|
|
throw new ArgumentException($"Value must be less or equal to {upper}", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void NotEmpty<TType>(IReadOnlyCollection<TType>? target, |
|
|
public static IReadOnlyCollection<TType> NotEmpty<TType>(IReadOnlyCollection<TType>? target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
NotNull(target, parameterName); |
|
|
NotNull(target, parameterName); |
|
|
@ -161,55 +185,78 @@ namespace Squidex.Infrastructure |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Collection does not contain an item.", parameterName); |
|
|
throw new ArgumentException("Collection does not contain an item.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target!; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void NotEmpty(Guid target, |
|
|
public static Guid NotEmpty(Guid target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
if (target == Guid.Empty) |
|
|
if (target == Guid.Empty) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Value cannot be empty.", parameterName); |
|
|
throw new ArgumentException("Value cannot be empty.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void NotEmpty(DomainId target, |
|
|
public static DomainId NotEmpty(DomainId target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
if (target == DomainId.Empty) |
|
|
if (target == DomainId.Empty) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Value cannot be empty.", parameterName); |
|
|
throw new ArgumentException("Value cannot be empty.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void NotNull(object? target, |
|
|
public static TValue NotNull<TValue>(TValue? target, |
|
|
|
|
|
[CallerArgumentExpression("target")] string? parameterName = null) where TValue : class |
|
|
|
|
|
{ |
|
|
|
|
|
if (target == null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new ArgumentNullException(parameterName); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
|
|
public static object? NotNull(object? target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
if (target == null) |
|
|
if (target == null) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentNullException(parameterName); |
|
|
throw new ArgumentNullException(parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void NotDefault<T>(T target, |
|
|
public static TValue NotDefault<TValue>(TValue target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
if (Equals(target, default(T)!)) |
|
|
if (Equals(target, default(TValue)!)) |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Value cannot be an the default value.", parameterName); |
|
|
throw new ArgumentException("Value cannot be an the default value.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void NotNullOrEmpty(string? target, |
|
|
public static string NotNullOrEmpty(string? target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
NotNull(target, parameterName); |
|
|
NotNull(target, parameterName); |
|
|
@ -218,11 +265,13 @@ namespace Squidex.Infrastructure |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("String parameter cannot be null or empty and cannot contain only blanks.", parameterName); |
|
|
throw new ArgumentException("String parameter cannot be null or empty and cannot contain only blanks.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[DebuggerStepThrough] |
|
|
[DebuggerStepThrough] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static void ValidFileName(string? target, |
|
|
public static string ValidFileName(string? target, |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
[CallerArgumentExpression("target")] string? parameterName = null) |
|
|
{ |
|
|
{ |
|
|
NotNullOrEmpty(target, parameterName); |
|
|
NotNullOrEmpty(target, parameterName); |
|
|
@ -231,6 +280,8 @@ namespace Squidex.Infrastructure |
|
|
{ |
|
|
{ |
|
|
throw new ArgumentException("Value contains an invalid character.", parameterName); |
|
|
throw new ArgumentException("Value contains an invalid character.", parameterName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return target!; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|