refactor: Rename ExceptionAssert.is_valid ExceptionAssert.Index.IsValid
Like the ExceptionAssert.Argument class that provides methods that throw ArgumentException if a condition isn't satisfied, the ExceptionAssert.Index class provides methods that throw IndexOutOfRange exceptions.
This commit is contained in:
1 parent
39b3490f5a
commit
fc050f4bd3
1 file changed
+14
-4
@@ -21,9 +21,19 @@ namespace mbts.utils {
|
||||
}
|
||||
#nullable disable
|
||||
|
||||
public static void index_valid(int index, int length) {
|
||||
if (index >= length) throw ExceptionBuilder.IndexOutOfRange.gte_length();
|
||||
if (index < 0) throw ExceptionBuilder.IndexOutOfRange.lt_zero();
|
||||
public static class Index {
|
||||
public static void IsValid(int index, int length, bool canInsert = false) {
|
||||
if (canInsert) {
|
||||
if (index > length) {
|
||||
throw ExceptionBuilder.IndexOutOfRange.gt_length();
|
||||
}
|
||||
} else if (index >= length) {
|
||||
throw ExceptionBuilder.IndexOutOfRange.gte_length();
|
||||
}
|
||||
if (index < 0) {
|
||||
throw ExceptionBuilder.IndexOutOfRange.lt_zero();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ArgumentCastor<T> Cast<T>(T argument) =>
|
||||
@@ -95,7 +105,7 @@ namespace mbts.utils {
|
||||
|
||||
public static void GreaterThanEqualTo<T>(T argument, T value, [CallerArgumentExpression(nameof(argument))] string name = "") where T : IComparable<T> {
|
||||
if (argument.CompareTo(value) < 0)
|
||||
throw new ArgumentException($"Must be greater than {value}.", name);
|
||||
throw new ArgumentException($"Must be at least {value}.", name);
|
||||
}
|
||||
|
||||
public static void NotNullGreaterThan<T>(T argument, T value, string name) where T : class, IComparable<T> {
|
||||
|
||||
Reference in new issue
Block a user