NucuCar/NucuCar.Domain/Guard.cs
2019-11-24 15:12:12 +02:00

38 lines
No EOL
1.7 KiB
C#

using System;
namespace NucuCar.Domain
{
/// <summary>
/// Helper class used for checking arguments and raise exception if the checks don't pass.
/// </summary>
public static class Guard
{
/// <summary>
/// Checks if the argument string is null or whitespace and raises exception on check fail.
/// </summary>
/// <param name="argumentName">The argument name that will be logged in the exception message.</param>
/// <param name="argument">The argument to check if it's null or whitespace.</param>
/// <exception cref="ArgumentNullException">Raised if the argument is null or whitespace.</exception>
internal static void ArgumentNotNullOrWhiteSpace(string argumentName, string argument)
{
if (string.IsNullOrWhiteSpace(argument))
{
throw new ArgumentNullException($"The argument {argumentName} is null or whitespace!");
}
}
/// <summary>
/// Checks if the argument is null and raises exception on check fail.
/// </summary>
/// <param name="argumentName">The argument name that will be logged in the exception message.</param>
/// <param name="argument">The argument to check if it's null.</param>
/// <exception cref="ArgumentNullException">Raised if the argument is null.</exception>
public static void ArgumentNotNull(string argumentName, object argument)
{
if (argument == null)
{
throw new ArgumentNullException($"The argument {argumentName} is null or whitespace!");
}
}
}
}