Skip to content

Commit c4ea675

Browse files
committed
Add annotated string.IsNullOr* replacements
Only netstandard2.1 has annotated APIs, so code that tested for nulls using these framework methods would trigger compiler warnings on subsequent dereferences. By using this annotated version instead, the analysis operates as expected. These methods should be inlined by the JIT leaving no runtime overhead.
1 parent 98ca00e commit c4ea675

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/NetMQ/Utils/Strings.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#nullable enable
2+
3+
using System.Diagnostics.CodeAnalysis;
4+
5+
namespace NetMQ
6+
{
7+
internal static class Strings
8+
{
9+
/// <inheritdoc cref="string.IsNullOrEmpty(string)"/>
10+
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)] string? s) => string.IsNullOrEmpty(s);
11+
12+
/// <inheritdoc cref="string.IsNullOrWhiteSpace(string)"/>
13+
public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)] string? s) => string.IsNullOrWhiteSpace(s);
14+
}
15+
}

0 commit comments

Comments
 (0)