From c5a2e17350c1481c496d405e124d97dfce7b61ec Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 9 Aug 2019 15:18:50 -0400 Subject: [PATCH] Fix IDE1005 (simplify delegate invocation) --- .../System/Diagnostics/Tracing/EventSource.cs | 14 +++----------- .../shared/System/IO/Stream.cs | 10 ++-------- .../shared/System/Progress.cs | 4 ++-- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs index 47ee18f7c865..df40519728cd 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs @@ -2782,9 +2782,7 @@ internal void DoCommand(EventCommandEventArgs commandArgs) } this.OnEventCommand(commandArgs); - var eventCommandCallback = this.m_eventCommandExecuted; - if (eventCommandCallback != null) - eventCommandCallback(this, commandArgs); + this.m_eventCommandExecuted?.Invoke(this, commandArgs); if (!commandArgs.enable) { @@ -2835,9 +2833,7 @@ internal void DoCommand(EventCommandEventArgs commandArgs) // Debug.Assert(matchAnyKeyword == EventKeywords.None); this.OnEventCommand(commandArgs); - var eventCommandCallback = m_eventCommandExecuted; - if (eventCommandCallback != null) - eventCommandCallback(this, commandArgs); + m_eventCommandExecuted?.Invoke(this, commandArgs); } } catch (Exception e) @@ -4255,11 +4251,7 @@ protected internal virtual void OnEventSourceCreated(EventSource eventSource) /// protected internal virtual void OnEventWritten(EventWrittenEventArgs eventData) { - EventHandler? callBack = this.EventWritten; - if (callBack != null) - { - callBack(this, eventData); - } + this.EventWritten?.Invoke(this, eventData); } diff --git a/src/System.Private.CoreLib/shared/System/IO/Stream.cs b/src/System.Private.CoreLib/shared/System/IO/Stream.cs index d1347d9f66c0..d02f2503dbb4 100644 --- a/src/System.Private.CoreLib/shared/System/IO/Stream.cs +++ b/src/System.Private.CoreLib/shared/System/IO/Stream.cs @@ -829,10 +829,7 @@ internal IAsyncResult BlockingBeginRead(byte[] buffer, int offset, int count, As asyncResult = new SynchronousAsyncResult(ex, state, isWrite: false); } - if (callback != null) - { - callback(asyncResult); - } + callback?.Invoke(asyncResult); return asyncResult; } @@ -861,10 +858,7 @@ internal IAsyncResult BlockingBeginWrite(byte[] buffer, int offset, int count, A asyncResult = new SynchronousAsyncResult(ex, state, isWrite: true); } - if (callback != null) - { - callback(asyncResult); - } + callback?.Invoke(asyncResult); return asyncResult; } diff --git a/src/System.Private.CoreLib/shared/System/Progress.cs b/src/System.Private.CoreLib/shared/System/Progress.cs index b6348bdb773c..e7535bcb9035 100644 --- a/src/System.Private.CoreLib/shared/System/Progress.cs +++ b/src/System.Private.CoreLib/shared/System/Progress.cs @@ -88,8 +88,8 @@ private void InvokeHandlers(object? state) Action? handler = _handler; EventHandler? changedEvent = ProgressChanged; - if (handler != null) handler(value); - if (changedEvent != null) changedEvent(this, value); + handler?.Invoke(value); + changedEvent?.Invoke(this, value); } }