Added FisheryLib.Collections.FishTable and Mono.Cecil extension methods
A bit of refactoring has been done too
This commit is contained in:
@@ -18,7 +18,8 @@ public partial class Guard
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or empty, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must be null or empty, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentNullException"/> or <see cref="ArgumentException"/> when <see cref="IsNotNullOrEmpty"/> fails.
|
||||
@@ -29,8 +30,10 @@ public partial class Guard
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
static Exception GetException(string? text, string name)
|
||||
=> text is null
|
||||
? new ArgumentNullException(name, $"Parameter {AssertString(name)} (string) must not be null or empty, was null.")
|
||||
: new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or empty, was empty.", name);
|
||||
? new ArgumentNullException(name,
|
||||
$"Parameter {AssertString(name)} (string) must not be null or empty, was null.")
|
||||
: new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must not be null or empty, was empty.", name);
|
||||
|
||||
throw GetException(text, name);
|
||||
}
|
||||
@@ -40,7 +43,8 @@ public partial class Guard
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNullOrWhiteSpace(string? text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must be null or whitespace, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must be null or whitespace, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotNullOrWhiteSpace"/> fails.
|
||||
@@ -51,8 +55,11 @@ public partial class Guard
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
static Exception GetException(string? text, string name)
|
||||
=> text is null
|
||||
? new ArgumentNullException(name, $"Parameter {AssertString(name)} (string) must not be null or whitespace, was null.")
|
||||
: new ArgumentException($"Parameter {AssertString(name)} (string) must not be null or whitespace, was whitespace.", name);
|
||||
? new ArgumentNullException(name,
|
||||
$"Parameter {AssertString(name)} (string) must not be null or whitespace, was null.")
|
||||
: new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must not be null or whitespace, was whitespace.",
|
||||
name);
|
||||
|
||||
throw GetException(text, name);
|
||||
}
|
||||
@@ -62,7 +69,8 @@ public partial class Guard
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsEmpty(string text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must be empty, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must be empty, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotEmpty"/> fails.
|
||||
@@ -76,83 +84,104 @@ public partial class Guard
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsWhiteSpace(string text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must be whitespace, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must be whitespace, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="IsNotWhiteSpace"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForIsNotWhiteSpace(string text, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must not be whitespace, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must not be whitespace, was {AssertString(text)}.", name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeEqualTo(string,int,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size equal to {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size equal to {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeNotEqualTo"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must not have a size equal to {size}, was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must not have a size equal to {size}, was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeGreaterThan"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size over {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size over {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeGreaterThanOrEqualTo"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size of at least {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size of at least {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeLessThan"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size less than {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeLessThanOrEqualTo(string,int,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name)
|
||||
=> throw new ArgumentException($"Parameter {AssertString(name)} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {AssertString(text)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"Parameter {AssertString(name)} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {AssertString(text)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeEqualTo(string,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name)
|
||||
=> throw new ArgumentException($"The source {AssertString(name)} (string) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}.", name);
|
||||
=> throw new ArgumentException(
|
||||
$"The source {AssertString(name)} (string) must have a size equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when <see cref="HasSizeLessThanOrEqualTo(string,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name)
|
||||
=> throw new ArgumentException($"The source {AssertString(name)} (string) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}.", name);
|
||||
public static void
|
||||
ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name)
|
||||
=> throw new ArgumentException(
|
||||
$"The source {AssertString(name)} (string) must have a size less than or equal to {AssertString(destination.Length)} (the destination), had a size of {AssertString(source.Length)}.",
|
||||
name);
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsInRangeFor(int,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(text.Length)} to be a valid index for the target string, was {AssertString(index)}.");
|
||||
=> throw new ArgumentOutOfRangeException(name, index,
|
||||
$"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(text.Length)} to be a valid index for the target string, was {AssertString(index)}.");
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="IsNotInRangeFor(int,string,string)"/> fails.
|
||||
/// </summary>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name)
|
||||
=> throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(text.Length)} to be an invalid index for the target string, was {AssertString(index)}.");
|
||||
=> throw new ArgumentOutOfRangeException(name, index,
|
||||
$"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(text.Length)} to be an invalid index for the target string, was {AssertString(index)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user