using System;
namespace S22.Sasl {
internal static class Extensions {
///
/// Adds a couple of useful extensions to reference types.
///
///
/// Throws an ArgumentNullException if the given data item is null.
///
/// The item to check for nullity.
/// The name to use when throwing an
/// exception, if necessary
public static void ThrowIfNull(this T data, string name)
where T : class {
if (data == null)
throw new ArgumentNullException(name);
}
///
/// Throws an ArgumentNullException if the given data item is null.
///
/// The item to check for nullity.
public static void ThrowIfNull(this T data)
where T : class {
if (data == null)
throw new ArgumentNullException();
}
///
/// Throws an ArgumentException if the given string is null or
/// empty.
///
/// The string to check for nullity and
/// emptiness.
public static void ThrowIfNullOrEmpty(this string data) {
if (String.IsNullOrEmpty(data))
throw new ArgumentException();
}
///
/// Throws an ArgumentException if the given string is null or
/// empty.
///
/// The string to check for nullity and
/// emptiness.
/// The name to use when throwing an
/// exception, if necessary
public static void ThrowIfNullOrEmpty(this string data, string name) {
if (String.IsNullOrEmpty(data))
throw new ArgumentException("The " + name +
" parameter must not be null or empty");
}
}
}