Skip to content

Commit aa4ea84

Browse files
committed
Add Assumes.NotNull
Sometimes the compiler cannot know that a reference is not null. Using this method instructs it, and validates the fact at runtime in debug builds.
1 parent c4ea675 commit aa4ea84

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/NetMQ/Utils/Assumes.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#nullable enable
2+
3+
using System.Diagnostics;
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace NetMQ
7+
{
8+
internal static class Assumes
9+
{
10+
#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.
11+
[Conditional("DEBUG")]
12+
public static void NotNull<T>([NotNull] T o) where T : class?
13+
{
14+
Debug.Assert(o is object);
15+
}
16+
#pragma warning restore CS8777 // Parameter must have a non-null value when exiting.
17+
}
18+
}

0 commit comments

Comments
 (0)