Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ContractUtils.cs
Go to the documentation of this file.
4
6
7internal static class ContractUtils
8{
9 [ExcludeFromCodeCoverage(Justification = "Unreachable")]
10 public static Exception Unreachable => new InvalidOperationException("Code supposed to be unreachable");
11
12 public static void Requires([DoesNotReturnIf(false)] bool precondition, string paramName)
13 {
14 if (!precondition)
15 {
17 }
18 }
19
20 public static void RequiresNotNull(object value, string paramName)
21 {
22 if (value == null)
23 {
25 }
26 }
27
28 public static void RequiresNotNull(object value, string paramName, int index)
29 {
30 if (value == null)
31 {
33 }
34 }
35
37 {
39 if (collection.Count == 0)
40 {
42 }
43 }
44
45 public static void RequiresNotNullItems<T>(IList<T> array, string arrayName)
46 {
48 int i = 0;
49 for (int count = array.Count; i < count; i++)
50 {
51 if (array[i] == null)
52 {
54 }
55 }
56 }
57
58 private static string GetParamName(string paramName, int index)
59 {
60 if (index < 0)
61 {
62 return paramName;
63 }
64 return $"{paramName}[{index}]";
65 }
66
67 public static void RequiresArrayRange<T>(IList<T> array, int offset, int count, string offsetName, string countName)
68 {
69 if (count < 0)
70 {
72 }
73 if (offset < 0 || array.Count - offset < count)
74 {
76 }
77 }
78}
static string GetParamName(string paramName, int index)
static void RequiresNotNull(object value, string paramName, int index)
static void RequiresNotEmpty< T >(ICollection< T > collection, string paramName)
static void Requires([DoesNotReturnIf(false)] bool precondition, string paramName)
static void RequiresArrayRange< T >(IList< T > array, int offset, int count, string offsetName, string countName)
static void RequiresNotNull(object value, string paramName)
static void RequiresNotNullItems< T >(IList< T > array, string arrayName)
static Exception NonEmptyCollectionRequired(string paramName)
Definition Error.cs:928
static Exception InvalidArgumentValue(string paramName)
Definition Error.cs:923