diff --git a/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs b/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs index 997a9e36d..2f9118477 100644 --- a/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs +++ b/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs @@ -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 Cast(T argument) => @@ -95,7 +105,7 @@ namespace mbts.utils { public static void GreaterThanEqualTo(T argument, T value, [CallerArgumentExpression(nameof(argument))] string name = "") where T : IComparable { 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 argument, T value, string name) where T : class, IComparable {