-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExceptionExtensions.cs
More file actions
41 lines (38 loc) · 1.22 KB
/
Copy pathExceptionExtensions.cs
File metadata and controls
41 lines (38 loc) · 1.22 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
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace TedToolkit.Assertions;
/// <summary>
/// Some exceptions extensions.
/// </summary>
public static class ExceptionExtensions
{
/// <summary>
/// Throw ArgumentNullException if obj is null.
/// </summary>
/// <param name="obj">The object</param>
/// <param name="objName">the name of obj</param>
/// <exception cref="ArgumentNullException">exceptions</exception>
[return: NotNull]
public static T ThrowIfNull<T>(
[NotNull] this T obj,
[CallerArgumentExpression(nameof(obj))]
string objName = "")
where T : class
{
return obj ?? throw new ArgumentNullException(objName);
}
/// <summary>
/// Throw ArgumentNullException if obj is null.
/// </summary>
/// <param name="obj">The object</param>
/// <param name="objName">the name of obj</param>
/// <exception cref="ArgumentNullException">exceptions</exception>
public static T ThrowIfNull<T>(
[NotNull] this T? obj,
[CallerArgumentExpression(nameof(obj))]
string objName = "")
where T : struct
{
return obj ?? throw new ArgumentNullException(objName);
}
}