-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Create guard clauses (#117)
- Loading branch information
1 parent
3e8a2b1
commit ac0cf7d
Showing
4 changed files
with
50 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace YeSql.Net; | ||
|
||
/// <summary> | ||
/// Helper methods to efficiently throw exceptions. | ||
/// </summary> | ||
internal class ThrowHelper | ||
{ | ||
/// <summary> | ||
/// Throws an <see cref="ArgumentNullException"/> if <c>argument</c> is <c>null</c>. | ||
/// </summary> | ||
/// <param name="argument"> | ||
/// The reference type argument to validate as non-null. | ||
/// </param> | ||
/// <param name="paramName"> | ||
/// The name of the parameter with which argument corresponds. | ||
/// </param> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
public static void ThrowIfNull(object argument, string paramName) | ||
{ | ||
if (argument is null) | ||
throw new ArgumentNullException(paramName); | ||
} | ||
|
||
/// <summary> | ||
/// Throws an exception if the <paramref name="argument"/> contains elements with a null value, | ||
/// an empty string, or consists only of white-space characters. | ||
/// </summary> | ||
/// <param name="argument"> | ||
/// The collection argument to validate. | ||
/// </param> | ||
/// <param name="paramName"> | ||
/// The name of the parameter with which argument corresponds. | ||
/// </param> | ||
/// <exception cref="ArgumentException"></exception> | ||
public static void ThrowIfContainsNullOrWhiteSpace(IEnumerable<string> argument, string paramName) | ||
{ | ||
if (argument.ContainsNullOrWhiteSpace()) | ||
{ | ||
var message = string.Format(ExceptionMessages.CollectionHasNullValueOrOnlyWhitespace, paramName); | ||
throw new ArgumentException(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters