diff options
Diffstat (limited to 'src/System.Private.CoreLib/shared/System/Threading/Tasks')
3 files changed, 9 insertions, 16 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs index e3339efd42..5cc0b6737b 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs @@ -597,14 +597,13 @@ namespace System.Threading.Tasks { // Invoke the delegate Debug.Assert(m_action != null); - var func = m_action as Func<TResult>; - if (func != null) + if (m_action is Func<TResult> func) { m_result = func(); return; } - var funcWithState = m_action as Func<object, TResult>; - if (funcWithState != null) + + if (m_action is Func<object, TResult> funcWithState) { m_result = funcWithState(m_stateObject); return; diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExceptionHolder.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExceptionHolder.cs index 0037923bdb..cdf5c78ea4 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExceptionHolder.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExceptionHolder.cs @@ -123,8 +123,7 @@ namespace System.Threading.Tasks // If this changes, make sure to only conditionally mark as handled below. // Store the cancellation exception - var oce = exceptionObject as OperationCanceledException; - if (oce != null) + if (exceptionObject is OperationCanceledException oce) { m_cancellationException = ExceptionDispatchInfo.Capture(oce); } @@ -155,24 +154,21 @@ namespace System.Threading.Tasks else Debug.Assert(exceptions.Count > 0, "Expected existing exceptions list to have > 0 exceptions."); // Handle Exception by capturing it into an ExceptionDispatchInfo and storing that - var exception = exceptionObject as Exception; - if (exception != null) + if (exceptionObject is Exception exception) { exceptions.Add(ExceptionDispatchInfo.Capture(exception)); } else { // Handle ExceptionDispatchInfo by storing it into the list - var edi = exceptionObject as ExceptionDispatchInfo; - if (edi != null) + if (exceptionObject is ExceptionDispatchInfo edi) { exceptions.Add(edi); } else { // Handle enumerables of exceptions by capturing each of the contained exceptions into an EDI and storing it - var exColl = exceptionObject as IEnumerable<Exception>; - if (exColl != null) + if (exceptionObject is IEnumerable<Exception> exColl) { #if DEBUG int numExceptions = 0; @@ -192,8 +188,7 @@ namespace System.Threading.Tasks else { // Handle enumerables of EDIs by storing them directly - var ediColl = exceptionObject as IEnumerable<ExceptionDispatchInfo>; - if (ediColl != null) + if (exceptionObject is IEnumerable<ExceptionDispatchInfo> ediColl) { exceptions.AddRange(ediColl); #if DEBUG diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs index c5bf02b9bc..13257b3077 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs @@ -500,8 +500,7 @@ namespace System.Threading.Tasks return null; // If it can be cast to an array, use it directly - Task[] activeTasksArray = activeTasksSource as Task[]; - if (activeTasksArray == null) + if (!(activeTasksSource is Task[] activeTasksArray)) { activeTasksArray = (new List<Task>(activeTasksSource)).ToArray(); } |