Skip to content

Commit 03c3783

Browse files
authored
Update NetMQMonitor.cs
Added handling of null case for reference types. (Previous code casted directly to the expected type, which will succeed for reference types, whereas the `is` operator will fail.)
1 parent 4f56cf3 commit 03c3783

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/NetMQ/Monitoring/NetMQMonitor.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,16 @@ private void Handle(object sender, NetMQSocketEventArgs socketEventArgs)
156156
{
157157
var monitorEvent = MonitorEvent.Read(m_monitoringSocket.SocketHandle);
158158

159-
T GetArg<T>() => monitorEvent.Arg is T v ? v : throw new ArgumentException($"Command argument must be of type {typeof(T).Name}.");
159+
T GetArg<T>()
160+
{
161+
if (monitorEvent.Arg is T v)
162+
return v;
163+
164+
if (monitorEvent.Arg == null && default(T) == null)
165+
return default(T);
166+
167+
throw new ArgumentException($"Command argument must be of type {typeof(T).Name}.");
168+
}
160169

161170
switch (monitorEvent.Event)
162171
{

0 commit comments

Comments
 (0)