-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
42 lines (39 loc) · 1.1 KB
/
Utils.cs
File metadata and controls
42 lines (39 loc) · 1.1 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.Runtime.CompilerServices;
using Serilog;
namespace ModShardPackerReference;
public static class Utils
{
// https://stackoverflow.com/questions/70430422/how-to-implicitly-convert-nullable-type-to-non-nullable-type
public static T ThrowIfNull<T>(
this T? argument,
string? message = default,
[CallerArgumentExpression("argument")] string? paramName = default
) where T : notnull
{
if (argument is null)
{
Log.Error("{0} is null.", argument);
throw new System.ArgumentNullException(paramName, message);
}
else
{
return argument;
}
}
public static T ThrowIfNull<T>(
this T? argument,
string? message = default,
[CallerArgumentExpression("argument")] string? paramName = default
) where T : unmanaged
{
if (argument is null)
{
Log.Error("{0} is null.", argument);
throw new System.ArgumentNullException(paramName, message);
}
else
{
return (T)argument;
}
}
}