Skip to content

Commit 6def659

Browse files
committed
Fix nullability warnings and annotations
1 parent 2f7ba60 commit 6def659

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/NetMQ.Tests/NetMQCertificateTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void X85()
1313
for (int i = 0; i < 1000; i++)
1414
{
1515
var key = new NetMQCertificate();
16-
var copy = new NetMQCertificate(key.SecretKeyZ85, key.PublicKeyZ85);
16+
var copy = new NetMQCertificate(key.SecretKeyZ85!, key.PublicKeyZ85);
1717

1818
Assert.Equal(key.SecretKeyZ85, copy.SecretKeyZ85);
1919
Assert.Equal(key.PublicKeyZ85, copy.PublicKeyZ85);
@@ -40,7 +40,7 @@ public void FromPublicKey()
4040
public void FromSecretKey()
4141
{
4242
var key = new NetMQCertificate();
43-
var copy = new NetMQCertificate().FromSecretKey(key.SecretKeyZ85);
43+
var copy = new NetMQCertificate().FromSecretKey(key.SecretKeyZ85!);
4444

4545
Assert.Equal(key.SecretKeyZ85, copy.SecretKeyZ85);
4646
Assert.Equal(key.PublicKeyZ85, copy.PublicKeyZ85);

src/NetMQ/NetMQActor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ private NetMQActor(PairSocket self, PairSocket shim, IShimHandler shimHandler)
149149
m_self = self;
150150
m_shim = shim;
151151

152-
void OnReceive(object sender, NetMQSocketEventArgs e) => m_receiveEvent.Fire(this, new NetMQActorEventArgs(this));
153-
void OnSend (object sender, NetMQSocketEventArgs e) => m_sendEvent .Fire(this, new NetMQActorEventArgs(this));
152+
void OnReceive(object sender, NetMQSocketEventArgs e) => m_receiveEvent!.Fire(this, new NetMQActorEventArgs(this));
153+
void OnSend (object sender, NetMQSocketEventArgs e) => m_sendEvent !.Fire(this, new NetMQActorEventArgs(this));
154154

155155
m_receiveEvent = new EventDelegator<NetMQActorEventArgs>(
156156
() => m_self.ReceiveReady += OnReceive,

src/NetMQ/NetMQBeacon.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Net;
34
using System.Net.Sockets;
5+
using System.Runtime.InteropServices;
46
using System.Text;
57
using System.Threading;
68
using NetMQ.Sockets;
7-
using System.Runtime.InteropServices;
89

910
namespace NetMQ
1011
{
@@ -199,7 +200,7 @@ private void OnUdpReady(Socket socket)
199200
{
200201
Assumes.NotNull(m_pipe);
201202

202-
if (!TryReceiveUdpFrame(out NetMQFrame frame, out string peerName))
203+
if (!TryReceiveUdpFrame(out NetMQFrame? frame, out string? peerName))
203204
return;
204205

205206
// If filter is set, check that beacon matches it
@@ -279,7 +280,7 @@ private void SendUdpFrame(NetMQFrame frame)
279280
}
280281
}
281282

282-
private bool TryReceiveUdpFrame(out NetMQFrame frame, out string peerName)
283+
private bool TryReceiveUdpFrame([NotNullWhen(returnValue: true)] out NetMQFrame? frame, [NotNullWhen(returnValue: true)] out string? peerName)
283284
{
284285
Assumes.NotNull(m_udpSocket);
285286

@@ -321,7 +322,7 @@ public NetMQBeacon()
321322
{
322323
m_actor = NetMQActor.Create(new Shim());
323324

324-
void OnReceive(object sender, NetMQActorEventArgs e) => m_receiveEvent.Fire(this, new NetMQBeaconEventArgs(this));
325+
void OnReceive(object sender, NetMQActorEventArgs e) => m_receiveEvent!.Fire(this, new NetMQBeaconEventArgs(this));
325326

326327
m_receiveEvent = new EventDelegator<NetMQBeaconEventArgs>(
327328
() => m_actor.ReceiveReady += OnReceive,

src/NetMQ/NetMQCertificate.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private string Z85Encode(byte[] data)
3636
{
3737
byte byte_nbr = 0;
3838
UInt32 value = 0;
39-
string dest = null;
39+
string? dest = null;
4040
while (byte_nbr<data.Length)
4141
{
4242
// Accumulate value in base 256 (binary)
@@ -53,7 +53,7 @@ private string Z85Encode(byte[] data)
5353
value = 0;
5454
}
5555
}
56-
return dest;
56+
return dest ?? "";
5757
}
5858

5959
/// <summary>
@@ -255,7 +255,7 @@ public static NetMQCertificate FromPublicKey(string publicKey)
255255
/// <summary>
256256
/// Curve Public key
257257
/// </summary>
258-
public string SecretKeyZ85 => SecretKey != null ? Z85Encode(SecretKey) : null;
258+
public string? SecretKeyZ85 => SecretKey != null ? Z85Encode(SecretKey) : null;
259259

260260

261261
/// <summary>

0 commit comments

Comments
 (0)