-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGuard.cs
More file actions
40 lines (33 loc) · 1.37 KB
/
Guard.cs
File metadata and controls
40 lines (33 loc) · 1.37 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
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
namespace ColorCode.Common
{
public static class Guard
{
public static void ArgNotNull(object arg, string paramName)
{
if (arg == null)
throw new ArgumentNullException(paramName);
}
public static void ArgNotNullAndNotEmpty(string arg, string paramName)
{
if (arg == null)
throw new ArgumentNullException(paramName);
if (string.IsNullOrEmpty(arg))
throw new ArgumentException(string.Format("The {0} argument value must not be empty.", paramName), paramName);
}
public static void EnsureParameterIsNotNullAndNotEmpty<TKey, TValue>(IDictionary<TKey, TValue> parameter, string parameterName)
{
if (parameter == null || parameter.Count == 0)
throw new ArgumentNullException(parameterName);
}
public static void ArgNotNullAndNotEmpty<T>(IList<T> arg, string paramName)
{
if (arg == null)
throw new ArgumentNullException(paramName);
if (arg.Count == 0)
throw new ArgumentException(string.Format("The {0} argument value must not be empty.", paramName), paramName);
}
}
}