This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ParameterTests.cs
47 lines (43 loc) · 2 KB
/
ParameterTests.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
using System.Reflection;
namespace System
{
internal static class ParameterTests
{
public static void NotNull<T>(this T @this, string paramName) where T : class
{
if (ReferenceEquals(@this, null))
{
#pragma warning disable HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
throw new ArgumentNullException(paramName, ErrorStrings.CannotBeNull(paramName));
#pragma warning restore HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
}
}
public static void NotNullOrEmpty(this string @this, string paramName)
{
if (string.IsNullOrEmpty(@this))
{
#pragma warning disable HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
throw new ArgumentNullException(paramName, ErrorStrings.CannotBeNullOrEmpty(paramName));
#pragma warning restore HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
}
}
public static void NotNullOrWhiteSpace(this string @this, string paramName)
{
if (string.IsNullOrWhiteSpace(@this))
{
#pragma warning disable HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
throw new ArgumentNullException(paramName, ErrorStrings.CannotBeNullOrWhitespace(paramName));
#pragma warning restore HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
}
}
public static void InstanceOf<T>(this T @this, string paramName, Type checkType)
{
if (!checkType.IsInstanceOfType(@this))
{
#pragma warning disable HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
throw new ArgumentException(ErrorStrings.MustBeReal(paramName, checkType), paramName);
#pragma warning restore HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
}
}
}
}