完善模型通用接口的无限层级一对一和单层级一对多
This commit is contained in:
@@ -13,44 +13,37 @@ public static class ThrowIf
|
||||
}
|
||||
}
|
||||
|
||||
public static T IsNull<T>([NotNull] T? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
|
||||
public static void IsNull<T>([NotNull] T? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw string.IsNullOrEmpty(msg) ? new ArgumentNullException(paraName) : new ArgumentException(msg);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static T IsNullOrDefault<T>([NotNull] T? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null) where T : struct
|
||||
public static void IsNullOrDefault<T>([NotNull] T? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null) where T : struct
|
||||
{
|
||||
if (!value.HasValue || value.Value.Equals(default(T)))
|
||||
{
|
||||
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空或默认值", paraName) : new ArgumentException(msg);
|
||||
}
|
||||
|
||||
return value.Value;
|
||||
}
|
||||
|
||||
|
||||
public static string IsNullOrWhiteSpace([NotNull] string? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
|
||||
public static void IsNullOrWhiteSpace([NotNull] string? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空或空格", paraName) : new ArgumentException(msg);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static string IsNullOrEmpty([NotNull] string? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
|
||||
public static void IsNullOrEmpty([NotNull] string? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空", paraName) : new ArgumentException(msg);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//public static ICollection<T> NotNullOrEmpty<T>(ICollection<T> value, string paraName)
|
||||
@@ -74,64 +67,52 @@ public static class ThrowIf
|
||||
// return type;
|
||||
//}
|
||||
|
||||
public static short OutOfRange(short value, string paraName, short minimumValue, short maximumValue = short.MaxValue)
|
||||
public static void OutOfRange(short value, string paraName, short minimumValue, short maximumValue = short.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int OutOfRange(int value, string paraName, int minimumValue, int maximumValue = int.MaxValue)
|
||||
public static void OutOfRange(int value, string paraName, int minimumValue, int maximumValue = int.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static long OutOfRange(long value, string paraName, long minimumValue, long maximumValue = long.MaxValue)
|
||||
public static void OutOfRange(long value, string paraName, long minimumValue, long maximumValue = long.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float OutOfRange(float value, string paraName, float minimumValue, float maximumValue = float.MaxValue)
|
||||
public static void OutOfRange(float value, string paraName, float minimumValue, float maximumValue = float.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static double OutOfRange(double value, string paraName, double minimumValue, double maximumValue = double.MaxValue)
|
||||
public static void OutOfRange(double value, string paraName, double minimumValue, double maximumValue = double.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static decimal OutOfRange(decimal value, string paraName, decimal minimumValue, decimal maximumValue = decimal.MaxValue)
|
||||
public static void OutOfRange(decimal value, string paraName, decimal minimumValue, decimal maximumValue = decimal.MaxValue)
|
||||
{
|
||||
if (value < minimumValue || value > maximumValue)
|
||||
{
|
||||
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user