feat: add method to throw if null or whitespace

This commit is contained in:
Stevan Freeborn
2024-06-30 12:03:21 -05:00
parent 0515afb1e0
commit 3298db7a3a
@@ -20,4 +20,19 @@ public static class ArgumentValidator
throw new ArgumentNullException(name);
}
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> if the value is null or empty.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="name">The name of the value.</param>
/// <exception cref="ArgumentException">Thrown when the value is null or empty.</exception>
/// <returns>Nothing.</returns>
public static void ThrowIfNullOrWhitespace(string value, string name)
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Value cannot be null or empty.", name);
}
}
}