-
Notifications
You must be signed in to change notification settings - Fork 1
/
Guard.cs
33 lines (27 loc) · 1.03 KB
/
Guard.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
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace Microsoft.MobCAT
{
public static class Guard
{
public static object Null(object value, [CallerMemberName]string propertyName = null)
{
if (value == null)
throw new ArgumentException($"Parameter {propertyName} cannot be null");
return value;
}
public static T Null<T>(T value, [CallerMemberName]string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(value, default(T)))
throw new ArgumentException($"Parameter {propertyName} cannot be null or default for type {typeof(T)}");
return value;
}
public static string NullOrWhitespace(string value, [CallerMemberName]string propertyName = null)
{
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException($"Parameter {propertyName} cannot be null or whitespace");
return value;
}
}
}