Skip to content

Commit

Permalink
Update NetMQMonitor.cs
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
mmillerbe authored Sep 24, 2020
1 parent 4f56cf3 commit 03c3783
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/NetMQ/Monitoring/NetMQMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,16 @@ private void Handle(object sender, NetMQSocketEventArgs socketEventArgs)
{
var monitorEvent = MonitorEvent.Read(m_monitoringSocket.SocketHandle);

T GetArg<T>() => monitorEvent.Arg is T v ? v : throw new ArgumentException($"Command argument must be of type {typeof(T).Name}.");
T GetArg<T>()
{
if (monitorEvent.Arg is T v)
return v;

if (monitorEvent.Arg == null && default(T) == null)
return default(T);

throw new ArgumentException($"Command argument must be of type {typeof(T).Name}.");
}

switch (monitorEvent.Event)
{
Expand Down

0 comments on commit 03c3783

Please sign in to comment.