forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssertExtensions.cs
More file actions
73 lines (58 loc) · 1.7 KB
/
AssertExtensions.cs
File metadata and controls
73 lines (58 loc) · 1.7 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections;
using System.Collections.Generic;
namespace ServiceStack.Common
{
public static class AssertExtensions
{
public static void ThrowOnFirstNull(params object[] objs)
{
foreach (var obj in objs)
{
ThrowIfNull(obj);
}
}
public static void ThrowIfNull(this object obj)
{
ThrowIfNull(obj, null);
}
public static void ThrowIfNull(this object obj, string varName)
{
if (obj == null)
throw new ArgumentNullException(varName ?? "object");
}
public static void ThrowIfNullOrEmpty(this string strValue)
{
ThrowIfNullOrEmpty(strValue, null);
}
public static void ThrowIfNullOrEmpty(this string strValue, string varName)
{
if (string.IsNullOrEmpty(strValue))
throw new ArgumentNullException(varName ?? "string");
}
public static void ThrowIfNullOrEmpty(this ICollection collection)
{
ThrowIfNullOrEmpty(collection, null);
}
public static void ThrowIfNullOrEmpty(this ICollection collection, string varName)
{
var fieldName = varName ?? "collection";
if (collection == null)
throw new ArgumentNullException(fieldName);
if (collection.Count == 0)
throw new ArgumentException(fieldName + " is empty");
}
public static void ThrowIfNullOrEmpty<T>(this ICollection<T> collection)
{
ThrowIfNullOrEmpty(collection, null);
}
public static void ThrowIfNullOrEmpty<T>(this ICollection<T> collection, string varName)
{
var fieldName = varName ?? "collection";
if (collection == null)
throw new ArgumentNullException(fieldName);
if (collection.Count == 0)
throw new ArgumentException(fieldName + " is empty");
}
}
}