From 96ec32e263c92a8d36ac98b677467bec064e4437 Mon Sep 17 00:00:00 2001 From: AoshiW Date: Sat, 5 Aug 2023 22:44:30 +0200 Subject: [PATCH] `catch when(...)` changes --- src/TwitchLib.Communication/Clients/TcpClient.cs | 6 ++---- src/TwitchLib.Communication/Clients/WebsocketClient.cs | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/TwitchLib.Communication/Clients/TcpClient.cs b/src/TwitchLib.Communication/Clients/TcpClient.cs index 7caee84..1bfc475 100644 --- a/src/TwitchLib.Communication/Clients/TcpClient.cs +++ b/src/TwitchLib.Communication/Clients/TcpClient.cs @@ -49,8 +49,7 @@ internal override async Task ListenTaskActionAsync() await RaiseMessage(new OnMessageEventArgs(input)); } - catch (Exception ex) when (ex.GetType() == typeof(TaskCanceledException) || - ex.GetType() == typeof(OperationCanceledException)) + catch (Exception ex) when (ex is TaskCanceledException or OperationCanceledException) { // occurs if the Tasks are canceled by the CancellationTokenSource.Token Logger?.LogExceptionAsInformation(GetType(), ex); @@ -143,8 +142,7 @@ protected override async Task ConnectClientAsync() _reader = new StreamReader(stream); _writer = new StreamWriter(stream); } - catch (Exception ex) when (ex.GetType() == typeof(TaskCanceledException) || - ex.GetType() == typeof(OperationCanceledException)) + catch (Exception ex) when (ex is TaskCanceledException or OperationCanceledException) { // occurs if the Tasks are canceled by the CancellationTokenSource.Token Logger?.LogExceptionAsInformation(GetType(), ex); diff --git a/src/TwitchLib.Communication/Clients/WebsocketClient.cs b/src/TwitchLib.Communication/Clients/WebsocketClient.cs index 125e971..516175e 100644 --- a/src/TwitchLib.Communication/Clients/WebsocketClient.cs +++ b/src/TwitchLib.Communication/Clients/WebsocketClient.cs @@ -184,8 +184,7 @@ protected override async Task ConnectClientAsync() Logger?.TraceAction(GetType(), "Client couldn't establish connection"); } } - catch (Exception ex) when (ex.GetType() == typeof(TaskCanceledException) || - ex.GetType() == typeof(OperationCanceledException)) + catch (Exception ex) when (ex is TaskCanceledException or OperationCanceledException) { // occurs if the Tasks are canceled by the CancellationTokenSource.Token Logger?.LogExceptionAsInformation(GetType(), ex);