Skip to content

Commit

Permalink
Better null handling in StandardIrcClient.ToString()
Browse files Browse the repository at this point in the history
  • Loading branch information
Crotalus committed Jul 29, 2024
1 parent 2eef4cb commit 1d3b798
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/IrcDotNet/StandardIrcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,14 @@ private void HandleSocketError(SocketException exception)
/// <returns>A string that represents this instance.</returns>
public override string ToString()
{
if (!IsDisposed && IsConnected)
return string.Format("{0}@{1}", LocalUser.UserName,
ServerName ?? socket.RemoteEndPoint.ToString());
return "(Not connected)";
if (IsDisposed) return "(Disposed)";
if (!IsConnected) return "(Not connected)";

var username = LocalUser?.UserName ?? "Unknown";
var serverInfo = ServerName ??
(socket?.RemoteEndPoint?.ToString() ?? "Unknown");

return $"{username}@{serverInfo}";
}

#if !SILVERLIGHT
Expand Down

0 comments on commit 1d3b798

Please sign in to comment.