-
Notifications
You must be signed in to change notification settings - Fork 9
/
Extensions.cs
55 lines (51 loc) · 1.68 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
namespace S22.Sasl {
internal static class Extensions {
/// <summary>
/// Adds a couple of useful extensions to reference types.
/// </summary>
/// <summary>
/// Throws an ArgumentNullException if the given data item is null.
/// </summary>
/// <param name="data">The item to check for nullity.</param>
/// <param name="name">The name to use when throwing an
/// exception, if necessary</param>
public static void ThrowIfNull<T>(this T data, string name)
where T : class {
if (data == null)
throw new ArgumentNullException(name);
}
/// <summary>
/// Throws an ArgumentNullException if the given data item is null.
/// </summary>
/// <param name="data">The item to check for nullity.</param>
public static void ThrowIfNull<T>(this T data)
where T : class {
if (data == null)
throw new ArgumentNullException();
}
/// <summary>
/// Throws an ArgumentException if the given string is null or
/// empty.
/// </summary>
/// <param name="data">The string to check for nullity and
/// emptiness.</param>
public static void ThrowIfNullOrEmpty(this string data) {
if (String.IsNullOrEmpty(data))
throw new ArgumentException();
}
/// <summary>
/// Throws an ArgumentException if the given string is null or
/// empty.
/// </summary>
/// <param name="data">The string to check for nullity and
/// emptiness.</param>
/// <param name="name">The name to use when throwing an
/// exception, if necessary</param>
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");
}
}
}