diff --git a/src/Microsoft.Management.UI.Internal/ManagementList/Common/Utilities.cs b/src/Microsoft.Management.UI.Internal/ManagementList/Common/Utilities.cs index f0308a8c2b..c6bcfcb173 100644 --- a/src/Microsoft.Management.UI.Internal/ManagementList/Common/Utilities.cs +++ b/src/Microsoft.Management.UI.Internal/ManagementList/Common/Utilities.cs @@ -90,7 +90,7 @@ namespace Microsoft.Management.UI.Internal foreach (object item in items) { - if (!(item is T)) + if (item is not T) { return false; } diff --git a/src/Microsoft.Management.UI.Internal/ShowCommand/Controls/ParameterSetControl.xaml.cs b/src/Microsoft.Management.UI.Internal/ShowCommand/Controls/ParameterSetControl.xaml.cs index c258a2819a..08f9df2933 100644 --- a/src/Microsoft.Management.UI.Internal/ShowCommand/Controls/ParameterSetControl.xaml.cs +++ b/src/Microsoft.Management.UI.Internal/ShowCommand/Controls/ParameterSetControl.xaml.cs @@ -357,7 +357,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal /// Will adding UIControl. private void AddControlToMainGrid(UIElement uiControl) { - if (this.firstFocusableElement == null && !(uiControl is Label)) + if (this.firstFocusableElement == null && uiControl is not Label) { this.firstFocusableElement = uiControl; } diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 36af765eeb..3b449f9145 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -142,7 +142,7 @@ namespace Microsoft.PowerShell.Commands holder.Reader != null, "All holders should have a reader assigned"); - if (_tailSpecified && !(holder.Reader is FileSystemContentReaderWriter)) + if (_tailSpecified && holder.Reader is not FileSystemContentReaderWriter) { string errMsg = SessionStateStrings.GetContent_TailNotSupported; ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "TailNotSupported", ErrorCategory.InvalidOperation, Tail); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index a7add8fcda..ad0bac503c 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -1897,7 +1897,7 @@ namespace Microsoft.PowerShell.Commands // Treat Strings and other single values as a StringContent. // If enumeration is false, also treat IEnumerables as StringContents. // String implements IEnumerable so the explicit check is required. - if (enumerate == false || fieldValue is string || !(fieldValue is IEnumerable)) + if (enumerate == false || fieldValue is string || fieldValue is not IEnumerable) { formData.Add(GetMultipartStringContent(fieldName: fieldName, fieldValue: fieldValue)); return; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs index a58af1b7f8..984ce18c73 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs @@ -419,7 +419,7 @@ namespace Microsoft.PowerShell.Commands { TraceListener listenerToRemove = source.Listeners[index]; - if (fileListenersOnly && !(listenerToRemove is TextWriterTraceListener)) + if (fileListenersOnly && listenerToRemove is not TextWriterTraceListener) { // Since we only want to remove file listeners, skip any that // aren't file listeners diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index e135e1681b..fd5898a48e 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -1868,7 +1868,7 @@ namespace Microsoft.PowerShell // If we're not going to continue, then get the exit code out of the runspace and // and indicate that it should be returned... - if (!_noExit && !(this.Runspace is RemoteRunspace)) + if (!_noExit && this.Runspace is not RemoteRunspace) { this.Runspace.ExecutionContext.ScriptCommandProcessorShouldRethrowExit = true; } diff --git a/src/System.Management.Automation/DscSupport/CimDSCParser.cs b/src/System.Management.Automation/DscSupport/CimDSCParser.cs index 6d264f76fc..1d6ff12f27 100644 --- a/src/System.Management.Automation/DscSupport/CimDSCParser.cs +++ b/src/System.Management.Automation/DscSupport/CimDSCParser.cs @@ -73,7 +73,9 @@ namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal MemberInfo[] memberInfo = targetType.GetMember(property.Name, BindingFlags.Public | BindingFlags.Instance); // verify property exists in corresponding class type - if (memberInfo == null || memberInfo.Length > 1 || !(memberInfo[0] is PropertyInfo || memberInfo[0] is FieldInfo)) + if (memberInfo == null + || memberInfo.Length > 1 + || (memberInfo[0] is not PropertyInfo && memberInfo[0] is not FieldInfo)) { errorMessage = string.Format(CultureInfo.CurrentCulture, ParserStrings.PropertyNotDeclaredInPSClass, new object[] { property.Name, className }); var invalidOperationException = new InvalidOperationException(errorMessage); diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs index 8b960e3229..505c766b9d 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs @@ -170,7 +170,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format return false; } - if (!(view.mainControl is ComplexControlBody) && !(view.mainControl is ListControlBody)) + if (view.mainControl is not ComplexControlBody && view.mainControl is not ListControlBody) { // Error at XPath {0} in file {1}: Out Of Band views can only have CustomControl or ListControl. ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.InvalidControlForOutOfBandView, ComputeCurrentXPath(), FilePath)); diff --git a/src/System.Management.Automation/cimSupport/cmdletization/xml/cmdlets-over-objects.xmlSerializer.autogen.cs b/src/System.Management.Automation/cimSupport/cmdletization/xml/cmdlets-over-objects.xmlSerializer.autogen.cs index f4892b51bc..a05d597999 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/xml/cmdlets-over-objects.xmlSerializer.autogen.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/xml/cmdlets-over-objects.xmlSerializer.autogen.cs @@ -2071,22 +2071,22 @@ namespace Microsoft.PowerShell.Cmdletization.Xml { if (ci == Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@RegularQuery && ((object)(ai) != null)) { - if (((object)ai) != null && !(ai is global::Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery)) throw CreateMismatchChoiceException(@"Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery", @"ItemsElementName", @"Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@RegularQuery"); + if (((object)ai) != null && ai is not global::Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery) throw CreateMismatchChoiceException(@"Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery", @"ItemsElementName", @"Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@RegularQuery"); Write13_WildcardablePropertyQuery(@"RegularQuery", @"http://schemas.microsoft.com/cmdlets-over-objects/2009/11", ((global::Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery)ai), false, false); } else if (ci == Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@ExcludeQuery && ((object)(ai) != null)) { - if (((object)ai) != null && !(ai is global::Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery)) throw CreateMismatchChoiceException(@"Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery", @"ItemsElementName", @"Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@ExcludeQuery"); + if (((object)ai) != null && ai is not global::Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery) throw CreateMismatchChoiceException(@"Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery", @"ItemsElementName", @"Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@ExcludeQuery"); Write13_WildcardablePropertyQuery(@"ExcludeQuery", @"http://schemas.microsoft.com/cmdlets-over-objects/2009/11", ((global::Microsoft.PowerShell.Cmdletization.Xml.WildcardablePropertyQuery)ai), false, false); } else if (ci == Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@MaxValueQuery && ((object)(ai) != null)) { - if (((object)ai) != null && !(ai is global::Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery)) throw CreateMismatchChoiceException(@"Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery", @"ItemsElementName", @"Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@MaxValueQuery"); + if (((object)ai) != null && ai is not global::Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery) throw CreateMismatchChoiceException(@"Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery", @"ItemsElementName", @"Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@MaxValueQuery"); Write14_PropertyQuery(@"MaxValueQuery", @"http://schemas.microsoft.com/cmdlets-over-objects/2009/11", ((global::Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery)ai), false, false); } else if (ci == Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@MinValueQuery && ((object)(ai) != null)) { - if (((object)ai) != null && !(ai is global::Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery)) throw CreateMismatchChoiceException(@"Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery", @"ItemsElementName", @"Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@MinValueQuery"); + if (((object)ai) != null && ai is not global::Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery) throw CreateMismatchChoiceException(@"Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery", @"ItemsElementName", @"Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType.@MinValueQuery"); Write14_PropertyQuery(@"MinValueQuery", @"http://schemas.microsoft.com/cmdlets-over-objects/2009/11", ((global::Microsoft.PowerShell.Cmdletization.Xml.PropertyQuery)ai), false, false); } else if ((object)(ai) != null) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs index f3347cdf4f..97c1f72101 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs @@ -627,7 +627,7 @@ namespace System.Management.Automation completionContext.ReplacementLength = replacementLength = 0; result = GetResultForAttributeArgument(completionContext, ref replacementIndex, ref replacementLength); } - else if (lastAst is HashtableAst hashTableAst && !(lastAst.Parent is DynamicKeywordStatementAst) && CheckForPendingAssignment(hashTableAst)) + else if (lastAst is HashtableAst hashTableAst && lastAst.Parent is not DynamicKeywordStatementAst && CheckForPendingAssignment(hashTableAst)) { // Handle scenarios such as 'gci | Format-Table @{Label=' if incomplete parsing of the assignment. return null; diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 611de0b584..13349c8b97 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -5050,7 +5050,7 @@ namespace System.Management.Automation memberName = memberNameAst.Value + "*"; } } - else if (!(lastAst is ErrorExpressionAst) && targetExpr == null) + else if (lastAst is not ErrorExpressionAst && targetExpr == null) { // I don't think we can complete anything interesting return results; @@ -6567,7 +6567,7 @@ namespace System.Management.Automation object value; if (SafeExprEvaluator.TrySafeEval(targetExpr, context.ExecutionContext, out value) && value != null) { - if (targetExpr is ArrayExpressionAst && !(value is object[])) + if (targetExpr is ArrayExpressionAst && value is not object[]) { // When the array contains only one element, the evaluation result would be that element. We wrap it into an array value = new[] { value }; diff --git a/src/System.Management.Automation/engine/CommandProcessor.cs b/src/System.Management.Automation/engine/CommandProcessor.cs index 1c0303ade3..be6b075656 100644 --- a/src/System.Management.Automation/engine/CommandProcessor.cs +++ b/src/System.Management.Automation/engine/CommandProcessor.cs @@ -319,7 +319,7 @@ namespace System.Management.Automation // NOTICE-2004/06/08-JonN 959638 using (commandRuntime.AllowThisCommandToWrite(true)) { - if (Context._debuggingMode > 0 && !(Command is PSScriptCmdlet)) + if (Context._debuggingMode > 0 && Command is not PSScriptCmdlet) { Context.Debugger.CheckCommand(this.Command.MyInvocation); } diff --git a/src/System.Management.Automation/engine/CommandProcessorBase.cs b/src/System.Management.Automation/engine/CommandProcessorBase.cs index 87fd4606c9..33804b69ae 100644 --- a/src/System.Management.Automation/engine/CommandProcessorBase.cs +++ b/src/System.Management.Automation/engine/CommandProcessorBase.cs @@ -517,7 +517,7 @@ namespace System.Management.Automation { SetCurrentScopeToExecutionScope(); - if (Context._debuggingMode > 0 && !(Command is PSScriptCmdlet)) + if (Context._debuggingMode > 0 && Command is not PSScriptCmdlet) { Context.Debugger.CheckCommand(this.Command.MyInvocation); } @@ -896,7 +896,7 @@ namespace System.Management.Automation // An explicit throw is written to $error as an ErrorRecord, so we // skip adding what is more or less a duplicate. - if (!(e is PipelineStoppedException) && !e.WasThrownFromThrowStatement) + if (e is not PipelineStoppedException && !e.WasThrownFromThrowStatement) commandRuntime.AppendErrorToVariables(e); } // Upstream cmdlets see only that execution stopped diff --git a/src/System.Management.Automation/engine/ExecutionContext.cs b/src/System.Management.Automation/engine/ExecutionContext.cs index 3fea333958..3a726be8f7 100644 --- a/src/System.Management.Automation/engine/ExecutionContext.cs +++ b/src/System.Management.Automation/engine/ExecutionContext.cs @@ -875,7 +875,7 @@ namespace System.Management.Automation internal void AppendDollarError(object obj) { ErrorRecord objAsErrorRecord = obj as ErrorRecord; - if (objAsErrorRecord == null && !(obj is Exception)) + if (objAsErrorRecord == null && obj is not Exception) { Diagnostics.Assert(false, "Object to append was neither an ErrorRecord nor an Exception in ExecutionContext.AppendDollarError"); return; diff --git a/src/System.Management.Automation/engine/GetCommandCommand.cs b/src/System.Management.Automation/engine/GetCommandCommand.cs index e71ed1218e..369ce76ad0 100644 --- a/src/System.Management.Automation/engine/GetCommandCommand.cs +++ b/src/System.Management.Automation/engine/GetCommandCommand.cs @@ -1320,7 +1320,9 @@ namespace Microsoft.PowerShell.Commands } } - if (ArgumentList != null && !(current is CmdletInfo || current is IScriptCommandInfo)) + if (ArgumentList != null + && current is not CmdletInfo + && current is not IScriptCommandInfo) { // If current is not a cmdlet or script, we need to throw a terminating error. ThrowTerminatingError( diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index 063e04d7a7..7906e3e2b0 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -1035,7 +1035,7 @@ namespace Microsoft.PowerShell.Commands _propertyOrMethodName, possibleMatches)); } - else if (methods.Count == 0 || !(methods[0] is PSMethodInfo)) + else if (methods.Count == 0 || methods[0] is not PSMethodInfo) { // write error record: method no found WriteError(GenerateNameParameterError( diff --git a/src/System.Management.Automation/engine/MinishellParameterBinderController.cs b/src/System.Management.Automation/engine/MinishellParameterBinderController.cs index cff1835278..bd23408fcf 100644 --- a/src/System.Management.Automation/engine/MinishellParameterBinderController.cs +++ b/src/System.Management.Automation/engine/MinishellParameterBinderController.cs @@ -99,7 +99,7 @@ namespace System.Management.Automation // Value of -Command parameter must be scriptblock var scriptBlockArgument = parameters[i]; var argumentValue = PSObject.Base(scriptBlockArgument.ArgumentValue); - if (!scriptBlockArgument.ArgumentSpecified || !(argumentValue is ScriptBlock)) + if (!scriptBlockArgument.ArgumentSpecified || argumentValue is not ScriptBlock) { throw NewParameterBindingException(null, ErrorCategory.InvalidArgument, CommandParameter, typeof(ScriptBlock), argumentValue.GetType(), diff --git a/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs b/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs index a61ffef50c..caa4a5a666 100644 --- a/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs +++ b/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs @@ -1360,7 +1360,7 @@ namespace System.Management.Automation try { // Only copy simple mutable variables... - if (v.Options == ScopedItemOptions.None && !(v is NullVariable)) + if (v.Options == ScopedItemOptions.None && v is not NullVariable) { PSVariable newVar = new PSVariable(v.Name, v.Value, v.Options, v.Description); // The variable is already defined/set in the scope, and that means the attributes diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index ea076c1142..975707bcf0 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -2384,7 +2384,10 @@ namespace System.Management.Automation // PipelineStoppedException should not get added to $Error // 2008/06/25 - narrieta: ExistNestedPromptException should not be added to $error either // 2019/10/18 - StopUpstreamCommandsException should not be added either - if (!(e is HaltCommandException) && !(e is PipelineStoppedException) && !(e is ExitNestedPromptException) && !(e is StopUpstreamCommandsException)) + if (e is not HaltCommandException + && e is not PipelineStoppedException + && e is not ExitNestedPromptException + && e is not StopUpstreamCommandsException) { try { diff --git a/src/System.Management.Automation/engine/MshObject.cs b/src/System.Management.Automation/engine/MshObject.cs index 460e62af69..b7e046ded2 100644 --- a/src/System.Management.Automation/engine/MshObject.cs +++ b/src/System.Management.Automation/engine/MshObject.cs @@ -2150,7 +2150,7 @@ namespace System.Management.Automation private bool MustDeferIDMOP() { var baseObject = PSObject.Base(Value); - return baseObject is IDynamicMetaObjectProvider && !(baseObject is PSObject); + return baseObject is IDynamicMetaObjectProvider && baseObject is not PSObject; } private DynamicMetaObject DeferForIDMOP(DynamicMetaObjectBinder binder, params DynamicMetaObject[] args) diff --git a/src/System.Management.Automation/engine/Pipe.cs b/src/System.Management.Automation/engine/Pipe.cs index c60ae52c9f..98b55cf110 100644 --- a/src/System.Management.Automation/engine/Pipe.cs +++ b/src/System.Management.Automation/engine/Pipe.cs @@ -510,7 +510,7 @@ namespace System.Management.Automation.Internal // If our object came from GetEnumerator (and hence is not IEnumerator), then we need to dispose // Otherwise, we don't own the object, so don't dispose. var disposable = ie as IDisposable; - if (disposable != null && !(objects is IEnumerator)) + if (disposable != null && objects is not IEnumerator) { disposable.Dispose(); } diff --git a/src/System.Management.Automation/engine/ScopedItemSearcher.cs b/src/System.Management.Automation/engine/ScopedItemSearcher.cs index 4361e39b05..fc67ee2637 100644 --- a/src/System.Management.Automation/engine/ScopedItemSearcher.cs +++ b/src/System.Management.Automation/engine/ScopedItemSearcher.cs @@ -274,7 +274,7 @@ namespace System.Management.Automation VariablePath name, out PSVariable variable) { - Diagnostics.Assert(!(name is FunctionLookupPath), + Diagnostics.Assert(name is not FunctionLookupPath, "name was scanned incorrect if we get here and it is a FunctionLookupPath"); bool result = true; @@ -328,7 +328,7 @@ namespace System.Management.Automation VariablePath name, out AliasInfo alias) { - Diagnostics.Assert(!(name is FunctionLookupPath), + Diagnostics.Assert(name is not FunctionLookupPath, "name was scanned incorrect if we get here and it is a FunctionLookupPath"); bool result = true; @@ -470,7 +470,7 @@ namespace System.Management.Automation VariablePath name, out PSDriveInfo drive) { - Diagnostics.Assert(!(name is FunctionLookupPath), + Diagnostics.Assert(name is not FunctionLookupPath, "name was scanned incorrect if we get here and it is a FunctionLookupPath"); bool result = true; diff --git a/src/System.Management.Automation/engine/hostifaces/Connection.cs b/src/System.Management.Automation/engine/hostifaces/Connection.cs index 2cb17f9bbd..29e86c91b9 100644 --- a/src/System.Management.Automation/engine/hostifaces/Connection.cs +++ b/src/System.Management.Automation/engine/hostifaces/Connection.cs @@ -650,7 +650,7 @@ namespace System.Management.Automation.Runspaces { get { - return !(this is LocalRunspace || ConnectionInfo == null); + return this is not LocalRunspace && ConnectionInfo != null; } } @@ -943,7 +943,8 @@ namespace System.Management.Automation.Runspaces case PipelineState.Completed: case PipelineState.Stopped: case PipelineState.Failed: - if (this.InNestedPrompt || !(this is RemoteRunspace) && this.Debugger.InBreakpoint) + if (this.InNestedPrompt + || (this is not RemoteRunspace && this.Debugger.InBreakpoint)) { this.RunspaceAvailability = RunspaceAvailability.AvailableForNestedCommand; } diff --git a/src/System.Management.Automation/engine/hostifaces/InternalHost.cs b/src/System.Management.Automation/engine/hostifaces/InternalHost.cs index 724b975e51..54897a99de 100644 --- a/src/System.Management.Automation/engine/hostifaces/InternalHost.cs +++ b/src/System.Management.Automation/engine/hostifaces/InternalHost.cs @@ -39,7 +39,7 @@ namespace System.Management.Automation.Internal.Host internal InternalHost(PSHost externalHost, ExecutionContext executionContext) { Dbg.Assert(externalHost != null, "must supply an PSHost"); - Dbg.Assert(!(externalHost is InternalHost), "try to create an InternalHost from another InternalHost"); + Dbg.Assert(externalHost is not InternalHost, "try to create an InternalHost from another InternalHost"); Dbg.Assert(executionContext != null, "must supply an ExecutionContext"); diff --git a/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs b/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs index a78f8e01bd..c8a0e9403e 100644 --- a/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs +++ b/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs @@ -987,7 +987,7 @@ namespace System.Management.Automation.Runspaces foreach (Job job in this.JobRepository.Jobs) { // Only stop or disconnect PowerShell jobs. - if (job is PSRemotingJob == false) + if (job is not PSRemotingJob) { continue; } diff --git a/src/System.Management.Automation/engine/hostifaces/pipelinebase.cs b/src/System.Management.Automation/engine/hostifaces/pipelinebase.cs index 64efdb12e4..3dfea3a2e3 100644 --- a/src/System.Management.Automation/engine/hostifaces/pipelinebase.cs +++ b/src/System.Management.Automation/engine/hostifaces/pipelinebase.cs @@ -491,7 +491,9 @@ namespace System.Management.Automation.Runspaces throw e; } - if (syncCall && !(InputStream is PSDataCollectionStream || InputStream is PSDataCollectionStream)) + if (syncCall + && InputStream is not PSDataCollectionStream + && InputStream is not PSDataCollectionStream) { // Method is called from synchronous invoke. if (input != null) diff --git a/src/System.Management.Automation/engine/interpreter/CallInstruction.cs b/src/System.Management.Automation/engine/interpreter/CallInstruction.cs index bcf3acc825..88ff4bc135 100644 --- a/src/System.Management.Automation/engine/interpreter/CallInstruction.cs +++ b/src/System.Management.Automation/engine/interpreter/CallInstruction.cs @@ -178,7 +178,7 @@ namespace System.Management.Automation.Interpreter private static bool ShouldCache(MethodInfo info) { - return !(info is DynamicMethod); + return info is not DynamicMethod; } /// diff --git a/src/System.Management.Automation/engine/parser/AstVisitor.cs b/src/System.Management.Automation/engine/parser/AstVisitor.cs index d87bb247a4..a20ea4a5ce 100644 --- a/src/System.Management.Automation/engine/parser/AstVisitor.cs +++ b/src/System.Management.Automation/engine/parser/AstVisitor.cs @@ -386,7 +386,7 @@ namespace System.Management.Automation.Language Type type = ast.TypeName.GetReflectionType(); if (type != null) { - Diagnostics.Assert(!(type is TypeBuilder), "ReflectionType can never be TypeBuilder"); + Diagnostics.Assert(type is not TypeBuilder, "ReflectionType can never be TypeBuilder"); } return AstVisitAction.Continue; diff --git a/src/System.Management.Automation/engine/parser/ConstantValues.cs b/src/System.Management.Automation/engine/parser/ConstantValues.cs index 5813ed9d41..dfc15d3bcd 100644 --- a/src/System.Management.Automation/engine/parser/ConstantValues.cs +++ b/src/System.Management.Automation/engine/parser/ConstantValues.cs @@ -261,7 +261,7 @@ namespace System.Management.Automation.Language public object VisitMemberExpression(MemberExpressionAst memberExpressionAst) { - if (!memberExpressionAst.Static || !(memberExpressionAst.Expression is TypeExpressionAst)) + if (!memberExpressionAst.Static || memberExpressionAst.Expression is not TypeExpressionAst) { return false; } diff --git a/src/System.Management.Automation/engine/parser/DebugViewWriter.cs b/src/System.Management.Automation/engine/parser/DebugViewWriter.cs index bc65cefa86..69e8aae634 100644 --- a/src/System.Management.Automation/engine/parser/DebugViewWriter.cs +++ b/src/System.Management.Automation/engine/parser/DebugViewWriter.cs @@ -470,7 +470,7 @@ namespace System.Management.Automation.Language { private static bool IsSimpleExpression(Expression node) { var binary = node as BinaryExpression; if (binary != null) { - return !(binary.Left is BinaryExpression || binary.Right is BinaryExpression); + return binary.Left is not BinaryExpression && binary.Right is not BinaryExpression; } return false; diff --git a/src/System.Management.Automation/engine/parser/Parser.cs b/src/System.Management.Automation/engine/parser/Parser.cs index fb57f12466..33ab679e80 100644 --- a/src/System.Management.Automation/engine/parser/Parser.cs +++ b/src/System.Management.Automation/engine/parser/Parser.cs @@ -1973,7 +1973,7 @@ namespace System.Management.Automation.Language } else if ((token.TokenFlags & TokenFlags.Keyword) != 0) { - foreach (var attr in attributes.Where(attr => !(attr is AttributeAst))) + foreach (var attr in attributes.Where(attr => attr is not AttributeAst)) { ReportError(attr.Extent, nameof(ParserStrings.TypeNotAllowedBeforeStatement), @@ -4923,7 +4923,8 @@ namespace System.Management.Automation.Language return new ErrorStatementAst(ExtentOf(usingToken, itemToken.Extent)); } - if (!(itemAst is StringConstantExpressionAst) && (kind != UsingStatementKind.Module || !(itemAst is HashtableAst))) + if (itemAst is not StringConstantExpressionAst + && (kind != UsingStatementKind.Module || itemAst is not HashtableAst)) { ReportError(ExtentFromFirstOf(itemAst, itemToken), nameof(ParserStrings.InvalidValueForUsingItemName), diff --git a/src/System.Management.Automation/engine/parser/SemanticChecks.cs b/src/System.Management.Automation/engine/parser/SemanticChecks.cs index 6f9ace8aae..a56e849811 100644 --- a/src/System.Management.Automation/engine/parser/SemanticChecks.cs +++ b/src/System.Management.Automation/engine/parser/SemanticChecks.cs @@ -197,7 +197,8 @@ namespace System.Management.Automation.Language var members = attributeType.GetMember(name, MemberTypes.Field | MemberTypes.Property, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); - if (members.Length != 1 || !(members[0] is PropertyInfo || members[0] is FieldInfo)) + if (members.Length != 1 + || (members[0] is not PropertyInfo && members[0] is not FieldInfo)) { _parser.ReportError(namedArg.Extent, nameof(ParserStrings.PropertyNotFoundForAttribute), @@ -348,7 +349,7 @@ namespace System.Management.Automation.Language { int count = 0; ITypeName type = typeName; - while ((type is TypeName) == false) + while (type is not TypeName) { count++; if (count > 200) @@ -1026,7 +1027,9 @@ namespace System.Management.Automation.Language } var memberExpr = exprAst as MemberExpressionAst; - if (memberExpr != null && !(memberExpr is InvokeMemberExpressionAst) && (memberExpr.Member is StringConstantExpressionAst)) + if (memberExpr != null + && memberExpr is not InvokeMemberExpressionAst + && memberExpr.Member is StringConstantExpressionAst) { return CheckUsingExpression(memberExpr.Expression); } @@ -1047,7 +1050,9 @@ namespace System.Management.Automation.Language public override AstVisitAction VisitVariableExpression(VariableExpressionAst variableExpressionAst) { - if (variableExpressionAst.Splatted && !(variableExpressionAst.Parent is CommandAst) && !(variableExpressionAst.Parent is UsingExpressionAst)) + if (variableExpressionAst.Splatted + && variableExpressionAst.Parent is not CommandAst + && variableExpressionAst.Parent is not UsingExpressionAst) { if (variableExpressionAst.Parent is ArrayLiteralAst && variableExpressionAst.Parent.Parent is CommandAst) { @@ -1214,7 +1219,9 @@ namespace System.Management.Automation.Language public override AstVisitAction VisitScriptBlock(ScriptBlockAst scriptBlockAst) { _scopeStack.Push(scriptBlockAst); - if (scriptBlockAst.Parent == null || scriptBlockAst.Parent is ScriptBlockExpressionAst || !(scriptBlockAst.Parent.Parent is FunctionMemberAst)) + if (scriptBlockAst.Parent == null + || scriptBlockAst.Parent is ScriptBlockExpressionAst + || scriptBlockAst.Parent.Parent is not FunctionMemberAst) { _memberScopeStack.Push(null); } @@ -1446,7 +1453,9 @@ namespace System.Management.Automation.Language var scriptBlockAst = ast as ScriptBlockAst; if (scriptBlockAst != null) { - if (scriptBlockAst.Parent == null || scriptBlockAst.Parent is ScriptBlockExpressionAst || !(scriptBlockAst.Parent.Parent is FunctionMemberAst)) + if (scriptBlockAst.Parent == null + || scriptBlockAst.Parent is ScriptBlockExpressionAst + || scriptBlockAst.Parent.Parent is not FunctionMemberAst) { _memberScopeStack.Pop(); } diff --git a/src/System.Management.Automation/engine/parser/ast.cs b/src/System.Management.Automation/engine/parser/ast.cs index 38f8478cb8..a15cf6e6a9 100644 --- a/src/System.Management.Automation/engine/parser/ast.cs +++ b/src/System.Management.Automation/engine/parser/ast.cs @@ -369,7 +369,7 @@ namespace System.Management.Automation.Language // Nested function isn't really a member of the type so stop looking // Anonymous script blocks are though var functionDefinitionAst = ast as FunctionDefinitionAst; - if (functionDefinitionAst != null && !(functionDefinitionAst.Parent is FunctionMemberAst)) + if (functionDefinitionAst != null && functionDefinitionAst.Parent is not FunctionMemberAst) break; ast = ast.Parent; } @@ -1581,7 +1581,7 @@ namespace System.Management.Automation.Language } // Make sure all statements are pipelines. - if (EndBlock.Statements.Any(ast => !(ast is PipelineAst))) + if (EndBlock.Statements.Any(ast => ast is not PipelineAst)) { errorId = "CanOnlyConvertOnePipeline"; errorMsg = AutomationExceptions.CanOnlyConvertOnePipeline; @@ -4019,7 +4019,7 @@ namespace System.Management.Automation.Language { this.CommandsAllowed = new ReadOnlyCollection(commandsAllowed.ToArray()); SetParents(CommandsAllowed); - this.HasNonConstantAllowedCommand = CommandsAllowed.Any(ast => !(ast is StringConstantExpressionAst)); + this.HasNonConstantAllowedCommand = CommandsAllowed.Any(ast => ast is not StringConstantExpressionAst); } else { diff --git a/src/System.Management.Automation/engine/parser/tokenizer.cs b/src/System.Management.Automation/engine/parser/tokenizer.cs index 717899d3bd..3d66362745 100644 --- a/src/System.Management.Automation/engine/parser/tokenizer.cs +++ b/src/System.Management.Automation/engine/parser/tokenizer.cs @@ -2110,7 +2110,7 @@ namespace System.Management.Automation.Language return; } - if (argumentValue is string || !(argumentValue is IEnumerable)) + if (argumentValue is string || argumentValue is not IEnumerable) { requiredEditions = HandleRequiresPSEditionArgument(argumentAst, argumentValue, ref requiredEditions); } @@ -2165,7 +2165,7 @@ namespace System.Management.Automation.Language } else if (assemblyToken.StartsWith(parameter.ParameterName, StringComparison.OrdinalIgnoreCase)) { - if (argumentValue is string || !(argumentValue is IEnumerable)) + if (argumentValue is string || argumentValue is not IEnumerable) { requiredAssemblies = HandleRequiresAssemblyArgument(argumentAst, argumentValue, requiredAssemblies); } diff --git a/src/System.Management.Automation/engine/remoting/client/Job.cs b/src/System.Management.Automation/engine/remoting/client/Job.cs index b86b6dc14b..03aa2d41d9 100644 --- a/src/System.Management.Automation/engine/remoting/client/Job.cs +++ b/src/System.Management.Automation/engine/remoting/client/Job.cs @@ -3382,9 +3382,10 @@ namespace System.Management.Automation fullyQualifiedErrorId, ErrorCategory.OpenError, null, null, null, null, null, errorDetails, null); } - else if ((pipeline.PipelineStateInfo.State == PipelineState.Failed) || - ((pipeline.PipelineStateInfo.State == PipelineState.Stopped) && - (pipeline.PipelineStateInfo.Reason != null && !(pipeline.PipelineStateInfo.Reason is PipelineStoppedException)))) + else if (pipeline.PipelineStateInfo.State == PipelineState.Failed + || (pipeline.PipelineStateInfo.State == PipelineState.Stopped + && pipeline.PipelineStateInfo.Reason != null + && pipeline.PipelineStateInfo.Reason is not PipelineStoppedException)) { // Pipeline stopped state is also an error condition if the associated exception is not 'PipelineStoppedException'. object targetObject = runspace.ConnectionInfo.ComputerName; diff --git a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs index 5771fc2d48..cbedc14c2a 100644 --- a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs +++ b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs @@ -156,8 +156,8 @@ namespace System.Management.Automation { // The RemoteRunspace object can only be constructed this way with a RunspacePool that // is in the disconnected state. - if ((runspacePool.RunspacePoolStateInfo.State != RunspacePoolState.Disconnected) || - !(runspacePool.ConnectionInfo is WSManConnectionInfo)) + if (runspacePool.RunspacePoolStateInfo.State != RunspacePoolState.Disconnected + || runspacePool.ConnectionInfo is not WSManConnectionInfo) { throw PSTraceSource.NewInvalidOperationException(RunspaceStrings.InvalidRunspacePool); } diff --git a/src/System.Management.Automation/engine/remoting/commands/ReceiveJob.cs b/src/System.Management.Automation/engine/remoting/commands/ReceiveJob.cs index aa804f6869..750edca6d7 100644 --- a/src/System.Management.Automation/engine/remoting/commands/ReceiveJob.cs +++ b/src/System.Management.Automation/engine/remoting/commands/ReceiveJob.cs @@ -768,7 +768,7 @@ namespace Microsoft.PowerShell.Commands // There is a bug in V2 that only remoting jobs work // with Receive-Job. This is being fixed - if (!(job is Job2) && job.UsesResultsCollection) + if (job is not Job2 && job.UsesResultsCollection) { // extract results and handle them Collection results = ReadAll(job.Results); diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs index 8a60ce277a..2c3a2c65b1 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs @@ -744,7 +744,7 @@ namespace System.Management.Automation.Remoting /// private static T SafelyGetBaseObject(PSObject psObject) { - if (psObject == null || psObject.BaseObject == null || !(psObject.BaseObject is T)) + if (psObject == null || psObject.BaseObject == null || psObject.BaseObject is not T) { throw RemoteHostExceptions.NewDecodingFailedException(); } @@ -771,7 +771,7 @@ namespace System.Management.Automation.Remoting private static T SafelyGetPropertyValue(PSObject psObject, string key) { PSPropertyInfo propertyInfo = psObject.Properties[key]; - if (propertyInfo == null || propertyInfo.Value == null || !(propertyInfo.Value is T)) + if (propertyInfo == null || propertyInfo.Value == null || propertyInfo.Value is not T) { throw RemoteHostExceptions.NewDecodingFailedException(); } diff --git a/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs b/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs index 07597fd79e..8507961795 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs @@ -1326,7 +1326,7 @@ namespace System.Management.Automation.Remoting private static bool IntegerTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path) { - if (!(obj is int) && !(obj is long)) + if (obj is not int && obj is not long) { cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeInteger, key, path)); return false; diff --git a/src/System.Management.Automation/engine/runtime/Binding/Binders.cs b/src/System.Management.Automation/engine/runtime/Binding/Binders.cs index 70790906e8..9ea707c67d 100644 --- a/src/System.Management.Automation/engine/runtime/Binding/Binders.cs +++ b/src/System.Management.Automation/engine/runtime/Binding/Binders.cs @@ -737,7 +737,11 @@ namespace System.Management.Automation.Language return null; } - if (!(obj is PSObject) && !(obj is IEnumerable) && !(obj is IEnumerator) && !(obj is DataTable) && !Marshal.IsComObject(obj)) + if (obj is not PSObject + && obj is not IEnumerable + && obj is not IEnumerator + && obj is not DataTable + && !Marshal.IsComObject(obj)) { return null; } @@ -885,7 +889,7 @@ namespace System.Management.Automation.Language restrictions)).WriteToDebugLog(this); } - bool needsToDispose = !(PSObject.Base(target.Value) is IEnumerator); + bool needsToDispose = PSObject.Base(target.Value) is not IEnumerator; return (new DynamicMetaObject( Expression.Call(CachedReflectionInfo.EnumerableOps_WriteEnumerableToPipe, enumerable.Expression, @@ -1722,7 +1726,8 @@ namespace System.Management.Automation.Language { var members = attributeType.GetMember(name, MemberTypes.Field | MemberTypes.Property, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); - if (members.Length != 1 || !(members[0] is PropertyInfo || members[0] is FieldInfo)) + if (members.Length != 1 + || (members[0] is not PropertyInfo && members[0] is not FieldInfo)) { return target.ThrowRuntimeError(args, BindingRestrictions.Empty, "PropertyNotFoundForType", ParserStrings.PropertyNotFoundForType, Expression.Constant(name), @@ -2011,7 +2016,7 @@ namespace System.Management.Automation.Language private static object ObjectRule(CallSite site, object obj) { - if (!(obj is ValueType) && !(obj is PSObject)) { return obj; } + if (obj is not ValueType && obj is not PSObject) { return obj; } return ((CallSite>)site).Update(site, obj); } @@ -3836,7 +3841,7 @@ namespace System.Management.Automation.Language var baseObject = PSObject.Base(argument.Value); // Source value cannot be null or AutomationNull, and it cannot be a pure PSObject. - if (baseObject != null && !(baseObject is PSObject)) + if (baseObject != null && baseObject is not PSObject) { Type fromType = baseObject.GetType(); ConversionRank rank = ConversionRank.None; @@ -4673,7 +4678,9 @@ namespace System.Management.Automation.Language } } - if (paramLength == 2 && setterParams[0].ParameterType == typeof(int) && !(target.Value is IDictionary)) + if (paramLength == 2 + && setterParams[0].ParameterType == typeof(int) + && target.Value is not IDictionary) { // PowerShell supports negative indexing for some types (specifically, those with a single // int parameter to the indexer, and also have either a Length or Count property.) For diff --git a/src/System.Management.Automation/help/MamlUtil.cs b/src/System.Management.Automation/help/MamlUtil.cs index 7ace664b72..3022d71f4a 100644 --- a/src/System.Management.Automation/help/MamlUtil.cs +++ b/src/System.Management.Automation/help/MamlUtil.cs @@ -206,7 +206,7 @@ namespace System.Management.Automation return propertyInfo; } - if (propertyInfo == null || !(propertyInfo.Value is PSObject)) + if (propertyInfo == null || propertyInfo.Value is not PSObject) { return null; } @@ -317,7 +317,7 @@ namespace System.Management.Automation } // If we are not on the last path element, let's make sure we can extend the path. - if (propertyInfo.Value == null || !(propertyInfo.Value is PSObject)) + if (propertyInfo.Value == null || propertyInfo.Value is not PSObject) { propertyInfo.Value = new PSObject(); } diff --git a/src/System.Management.Automation/utils/PowerShellExecutionHelper.cs b/src/System.Management.Automation/utils/PowerShellExecutionHelper.cs index d6d845c728..dcfc2682bc 100644 --- a/src/System.Management.Automation/utils/PowerShellExecutionHelper.cs +++ b/src/System.Management.Automation/utils/PowerShellExecutionHelper.cs @@ -189,7 +189,7 @@ namespace System.Management.Automation if (pso != null) { object baseObject = pso.BaseObject; - if (baseObject != null && !(baseObject is PSCustomObject)) + if (baseObject != null && baseObject is not PSCustomObject) result = baseObject.ToString(); else result = pso.ToString();