/
Check.cs
53 lines (47 loc) · 1.18 KB
/
Check.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
namespace DeadMosquito.AndroidGoodies.Internal
{
using System;
static class Check
{
public delegate bool Condition();
public static void IsTrue(Condition condition, string message = "")
{
if (!condition())
{
throw new ArgumentException(message);
}
}
public static class Argument
{
public static void IsNotNull(object argument, string argumentName, string message = "")
{
if (string.IsNullOrEmpty(message))
{
message = string.Format("[{0}] must not be null or empty", argumentName);
}
if (argument == null)
{
throw new ArgumentNullException(argumentName, message);
}
}
public static void IsStrNotNullOrEmpty(string argument, string argumentName, string message = null)
{
if (string.IsNullOrEmpty(argument))
{
if (message == null)
{
message = string.Format("[{0}] must not be null or empty", argumentName);
}
throw new ArgumentException(message, argumentName);
}
}
public static void IsNotNegative(int argument, string argumentName)
{
if (argument < 0)
{
throw new ArgumentOutOfRangeException(argumentName, argumentName + " must not be negative.");
}
}
}
}
}