diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs index 9cf9589326a..afadd0a3fe4 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs @@ -404,7 +404,7 @@ protected object GetReferenceOrReferenceArrayObject(object value, ref CimType re { return null; } - else if (!(cimReferenceArray[0] is PSReference)) + else if (cimReferenceArray[0] is not PSReference) { return null; } diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs index 084bad51d91..df4cfc2b645 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs @@ -1055,7 +1055,7 @@ private static void AddShowComputerNameMarker(object o) } PSObject pso = PSObject.AsPSObject(o); - if (!(pso.BaseObject is CimInstance)) + if (pso.BaseObject is not CimInstance) { return; } @@ -2086,7 +2086,7 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args) { DebugHelper.WriteLogEx(); - if (!(args.Action is CimWriteResultObject)) + if (args.Action is not CimWriteResultObject) { // allow all other actions return true; @@ -2240,7 +2240,7 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args) { DebugHelper.WriteLogEx(); - if (!(args.Action is CimWriteResultObject)) + if (args.Action is not CimWriteResultObject) { // allow all other actions return true; diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/clientSideQuery.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/clientSideQuery.cs index 001b311e82a..e686b4e3b16 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/clientSideQuery.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/clientSideQuery.cs @@ -405,7 +405,7 @@ public bool IsMatch(CimInstance o) private object ConvertActualValueToExpectedType(object actualPropertyValue, object expectedPropertyValue) { - if ((actualPropertyValue is string) && (!(expectedPropertyValue is string))) + if (actualPropertyValue is string && expectedPropertyValue is not string) { actualPropertyValue = LanguagePrimitives.ConvertTo(actualPropertyValue, expectedPropertyValue.GetType(), CultureInfo.InvariantCulture); } 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 f38446ed57f..68c69d982a7 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 @@ -667,7 +667,7 @@ internal virtual void PrepareSession() // null is not valid value for header. // We silently ignore header if value is null. - if (!(value is null)) + if (value is not null) { // add the header value (or overwrite it if already present) WebSession.Headers[key] = value.ToString(); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs index 12f8e5b4e09..04e35a9018d 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs @@ -525,7 +525,7 @@ private static ErrorRecord ConvertToErrorRecord(object obj) if (mshobj != null) { object baseObject = mshobj.BaseObject; - if (!(baseObject is PSCustomObject)) + if (baseObject is not PSCustomObject) { obj = baseObject; } diff --git a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs index be45b0d8d84..6e12fcb0f63 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs @@ -75,7 +75,7 @@ public override bool Equals(object obj) if (obj == null) return false; - if (!(obj is PropertyKey)) + if (obj is not PropertyKey) return false; PropertyKey other = (PropertyKey)obj; diff --git a/src/Microsoft.PowerShell.ScheduledJob/ScheduledJobDefinition.cs b/src/Microsoft.PowerShell.ScheduledJob/ScheduledJobDefinition.cs index 650c643ecf9..175c4fdaa56 100644 --- a/src/Microsoft.PowerShell.ScheduledJob/ScheduledJobDefinition.cs +++ b/src/Microsoft.PowerShell.ScheduledJob/ScheduledJobDefinition.cs @@ -938,7 +938,7 @@ public void Register() { } } - if (!(ex is ScheduledJobException)) + if (ex is not ScheduledJobException) { // Wrap in ScheduledJobException type. string msg = StringUtil.Format(ScheduledJobErrorStrings.ErrorRegisteringDefinitionStore, this.Name); diff --git a/src/Microsoft.PowerShell.Security/security/AclCommands.cs b/src/Microsoft.PowerShell.Security/security/AclCommands.cs index 03fa060154b..74962b36e8c 100644 --- a/src/Microsoft.PowerShell.Security/security/AclCommands.cs +++ b/src/Microsoft.PowerShell.Security/security/AclCommands.cs @@ -783,7 +783,7 @@ protected override void ProcessRecord() { customDescriptor = PSObject.Base(methodInfo.Invoke()); - if (!(customDescriptor is FileSystemSecurity)) + if (customDescriptor is not FileSystemSecurity) { customDescriptor = new CommonSecurityDescriptor(false, false, customDescriptor.ToString()); } diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index 3436ddb6062..d0a589bb1cb 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -1195,7 +1195,7 @@ protected override bool ItemExists(string path) // If the inner exception is not of that type // then we need to rethrow // - if (!(e.InnerException is CertificateProviderItemNotFoundException)) + if (e.InnerException is not CertificateProviderItemNotFoundException) { throw; } diff --git a/src/System.Management.Automation/FormatAndOutput/out-console/OutConsole.cs b/src/System.Management.Automation/FormatAndOutput/out-console/OutConsole.cs index e7afeda5e15..edf9e5ef8f1 100644 --- a/src/System.Management.Automation/FormatAndOutput/out-console/OutConsole.cs +++ b/src/System.Management.Automation/FormatAndOutput/out-console/OutConsole.cs @@ -109,11 +109,10 @@ protected override void ProcessRecord() object inputObjectBase = PSObject.Base(InputObject); // Ignore errors and formatting records, as those can't be captured - if ( - (inputObjectBase != null) && - (!(inputObjectBase is ErrorRecord)) && - (!inputObjectBase.GetType().FullName.StartsWith( - "Microsoft.PowerShell.Commands.Internal.Format", StringComparison.OrdinalIgnoreCase))) + if (inputObjectBase != null && + inputObjectBase is not ErrorRecord && + !inputObjectBase.GetType().FullName.StartsWith( + "Microsoft.PowerShell.Commands.Internal.Format", StringComparison.OrdinalIgnoreCase)) { _outVarResults.Add(InputObject); } diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs index bbc85aa4003..ed0c1309cc1 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs @@ -1805,7 +1805,7 @@ private List GetResultForIdentifier(CompletionContext completi } } // Continue trying the filename/commandname completion for scenarios like this: $aa[get- - else if (!(cursorAst is ErrorExpressionAst && cursorAst.Parent is IndexExpressionAst)) + else if (cursorAst is not ErrorExpressionAst || cursorAst.Parent is not IndexExpressionAst) { return result; } diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index b6c7d88a111..a3c5b2053ef 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -1895,7 +1895,7 @@ private static IEnumerable NativeCommandArgumentCompletion_InferType yield return new PSTypeName(pso.TypeNames[0]); } - if (!(pso.BaseObject is PSCustomObject)) + if (pso.BaseObject is not PSCustomObject) { yield return new PSTypeName(pso.BaseObject.GetType()); } @@ -7140,7 +7140,7 @@ IEnumerable IArgumentCompleter.CompleteArgument( CommandAst commandAst, IDictionary fakeBoundParameters) { - if (!(commandAst.Parent is PipelineAst pipelineAst)) + if (commandAst.Parent is not PipelineAst pipelineAst) { return null; } diff --git a/src/System.Management.Automation/engine/CompiledCommandParameter.cs b/src/System.Management.Automation/engine/CompiledCommandParameter.cs index ba4fa1fbb21..b533c365cbd 100644 --- a/src/System.Management.Automation/engine/CompiledCommandParameter.cs +++ b/src/System.Management.Automation/engine/CompiledCommandParameter.cs @@ -69,7 +69,7 @@ internal CompiledCommandParameter(RuntimeDefinedParameter runtimeDefinedParamete } } - if (!(attribute is ArgumentTypeConverterAttribute)) + if (attribute is not ArgumentTypeConverterAttribute) { ProcessAttribute(runtimeDefinedParameter.Name, attribute, ref validationAttributes, ref argTransformationAttributes, ref aliases); } diff --git a/src/System.Management.Automation/engine/EventManager.cs b/src/System.Management.Automation/engine/EventManager.cs index a962f745eac..e2cb546376c 100644 --- a/src/System.Management.Automation/engine/EventManager.cs +++ b/src/System.Management.Automation/engine/EventManager.cs @@ -2597,7 +2597,7 @@ internal void Invoke(PSEventSubscriber eventSubscriber, PSEventArgs eventArgs) catch (Exception e) { // Catch-all OK. This is a third-party call-out. - if (!(e is PipelineStoppedException)) + if (e is not PipelineStoppedException) { LogErrorsAndOutput(results, actionState); SetJobState(JobState.Failed); diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 43c21f512c1..1e4b74fcfa8 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -906,7 +906,7 @@ public static bool TryCompare(object first, object second, bool ignoreCase, IFor formatProvider = CultureInfo.InvariantCulture; } - if (!(formatProvider is CultureInfo culture)) + if (formatProvider is not CultureInfo culture) { throw PSTraceSource.NewArgumentException(nameof(formatProvider)); } @@ -936,7 +936,7 @@ public static bool TryCompare(object first, object second, bool ignoreCase, IFor if (first is string firstString) { - if (!(second is string secondString)) + if (second is not string secondString) { if (!TryConvertTo(second, culture, out secondString)) { @@ -4283,7 +4283,7 @@ public override int GetHashCode() public override bool Equals(object other) { - if (!(other is ConversionTypePair)) + if (other is not ConversionTypePair) return false; var ctp = (ConversionTypePair)other; diff --git a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs index 8ee68283ec6..77dab2bd551 100644 --- a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs +++ b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs @@ -628,7 +628,7 @@ private IEnumerable PreProcessModuleSpec(IEnumerable moduleSpecs) { foreach (object spec in moduleSpecs) { - if (!(spec is Hashtable)) + if (spec is not Hashtable) { yield return spec.ToString(); } diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index b67d2d861a5..af4716f3309 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -953,7 +953,7 @@ internal void SetupOutVariable() _outVarList = oldValue ?? new ArrayList(); - if (!(_thisCommand is PSScriptCmdlet)) + if (_thisCommand is not PSScriptCmdlet) { this.OutputPipe.AddVariableList(VariableStreamKind.Output, _outVarList); } @@ -989,7 +989,7 @@ internal void SetupPipelineVariable() // same scope. _pipelineVarReference = _state.PSVariable.Get(this.PipelineVariable); - if (!(_thisCommand is PSScriptCmdlet)) + if (_thisCommand is not PSScriptCmdlet) { this.OutputPipe.SetPipelineVariable(_pipelineVarReference); } @@ -2574,7 +2574,7 @@ internal void SetupVariable(VariableStreamKind streamKind, string variableName, varList = new ArrayList(); } - if (!(_thisCommand is PSScriptCmdlet)) + if (_thisCommand is not PSScriptCmdlet) { this.OutputPipe.AddVariableList(streamKind, varList); } diff --git a/src/System.Management.Automation/engine/MshMemberInfo.cs b/src/System.Management.Automation/engine/MshMemberInfo.cs index 451048e2018..cb75b1519ce 100644 --- a/src/System.Management.Automation/engine/MshMemberInfo.cs +++ b/src/System.Management.Automation/engine/MshMemberInfo.cs @@ -183,7 +183,7 @@ internal virtual void ReplicateInstance(object particularInstance) internal void SetValueNoConversion(object setValue) { - if (!(this is PSProperty thisAsProperty)) + if (this is not PSProperty thisAsProperty) { this.Value = setValue; return; @@ -552,7 +552,7 @@ private void LookupMember(string name, HashSet visitedAliases, out PSMem name); } - if (!(member is PSAliasProperty aliasMember)) + if (member is not PSAliasProperty aliasMember) { hasCycle = false; returnedMember = member; diff --git a/src/System.Management.Automation/engine/TypeTable.cs b/src/System.Management.Automation/engine/TypeTable.cs index c5b889b2586..74b2f6910f8 100644 --- a/src/System.Management.Automation/engine/TypeTable.cs +++ b/src/System.Management.Automation/engine/TypeTable.cs @@ -2191,7 +2191,7 @@ public TypeMemberData StringSerializationSourceProperty return; } - if (!(value is NotePropertyData || value is ScriptPropertyData || value is CodePropertyData)) + if (value is not NotePropertyData && value is not ScriptPropertyData && value is not CodePropertyData) { throw PSTraceSource.NewArgumentException("value"); } diff --git a/src/System.Management.Automation/engine/debugger/debugger.cs b/src/System.Management.Automation/engine/debugger/debugger.cs index d19815ac303..8fed757e725 100644 --- a/src/System.Management.Automation/engine/debugger/debugger.cs +++ b/src/System.Management.Automation/engine/debugger/debugger.cs @@ -4945,7 +4945,7 @@ private string FixUpStatementExtent(int startColNum, string stateExtentText) private object DrainAndBlockRemoteOutput() { // We only do this for remote runspaces. - if (!(_runspace is RemoteRunspace)) { return null; } + if (_runspace is not RemoteRunspace) { return null; } try { diff --git a/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs b/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs index cffbc6d81a1..4b933b590b9 100644 --- a/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs +++ b/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs @@ -268,7 +268,7 @@ private void CoreOpen(bool syncCall) // sometimes there are many runspaces created - the callee ensures telemetry is only // reported once. Note that if the host implements IHostProvidesTelemetryData, we rely // on the host calling ReportStartupTelemetry. - if (!(this.Host is IHostProvidesTelemetryData)) + if (this.Host is not IHostProvidesTelemetryData) { TelemetryAPI.ReportStartupTelemetry(null); } diff --git a/src/System.Management.Automation/engine/hostifaces/ConnectionFactory.cs b/src/System.Management.Automation/engine/hostifaces/ConnectionFactory.cs index 2021ae6abf9..b812e8fe82b 100644 --- a/src/System.Management.Automation/engine/hostifaces/ConnectionFactory.cs +++ b/src/System.Management.Automation/engine/hostifaces/ConnectionFactory.cs @@ -454,11 +454,11 @@ public static RunspacePool CreateRunspacePool(int minRunspaces, public static RunspacePool CreateRunspacePool(int minRunspaces, int maxRunspaces, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) { - if ((!(connectionInfo is WSManConnectionInfo)) && - (!(connectionInfo is NewProcessConnectionInfo)) && - (!(connectionInfo is NamedPipeConnectionInfo)) && - (!(connectionInfo is VMConnectionInfo)) && - (!(connectionInfo is ContainerConnectionInfo))) + if (connectionInfo is not WSManConnectionInfo && + connectionInfo is not NewProcessConnectionInfo && + connectionInfo is not NamedPipeConnectionInfo && + connectionInfo is not VMConnectionInfo && + connectionInfo is not ContainerConnectionInfo) { throw new NotSupportedException(); } @@ -539,12 +539,12 @@ public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSH /// public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments, string name) { - if ((!(connectionInfo is WSManConnectionInfo)) && - (!(connectionInfo is NewProcessConnectionInfo)) && - (!(connectionInfo is NamedPipeConnectionInfo)) && - (!(connectionInfo is SSHConnectionInfo)) && - (!(connectionInfo is VMConnectionInfo)) && - (!(connectionInfo is ContainerConnectionInfo))) + if (connectionInfo is not WSManConnectionInfo && + connectionInfo is not NewProcessConnectionInfo && + connectionInfo is not NamedPipeConnectionInfo && + connectionInfo is not SSHConnectionInfo && + connectionInfo is not VMConnectionInfo && + connectionInfo is not ContainerConnectionInfo) { throw new NotSupportedException(); } @@ -606,4 +606,3 @@ public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable, PowerShel #endregion V3 Extensions } } - diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index 9345462aa56..a88692a91e7 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -1459,7 +1459,7 @@ void ProcessRecord() { PSObject serializedPipelineState = pipelineState as PSObject; object baseObject = serializedPipelineState.BaseObject; - if (!(baseObject is int)) + if (baseObject is not int) { break; } diff --git a/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs b/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs index 13448528be5..dfd33cc2257 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs @@ -1634,7 +1634,7 @@ private static void VerifyValueType(object value) throw PSTraceSource.NewArgumentNullException(nameof(value), PSDataBufferStrings.ValueNullReference); } } - else if (!(value is T)) + else if (value is not T) { throw PSTraceSource.NewArgumentException(nameof(value), PSDataBufferStrings.CannotConvertToGenericType, value.GetType().FullName, diff --git a/src/System.Management.Automation/engine/hostifaces/RunspacePool.cs b/src/System.Management.Automation/engine/hostifaces/RunspacePool.cs index 3c88f8b9ff7..9f281f2956a 100644 --- a/src/System.Management.Automation/engine/hostifaces/RunspacePool.cs +++ b/src/System.Management.Automation/engine/hostifaces/RunspacePool.cs @@ -638,7 +638,7 @@ internal RunspacePool( TypeTable typeTable) { // Disconnect-Connect semantics are currently only supported in WSMan transport. - if (!(connectionInfo is WSManConnectionInfo)) + if (connectionInfo is not WSManConnectionInfo) { throw new NotSupportedException(); } diff --git a/src/System.Management.Automation/engine/interpreter/CallInstruction.cs b/src/System.Management.Automation/engine/interpreter/CallInstruction.cs index d351a08bfd4..bcf3acc8251 100644 --- a/src/System.Management.Automation/engine/interpreter/CallInstruction.cs +++ b/src/System.Management.Automation/engine/interpreter/CallInstruction.cs @@ -104,7 +104,7 @@ public static CallInstruction Create(MethodInfo info, ParameterInfo[] parameters } catch (TargetInvocationException tie) { - if (!(tie.InnerException is NotSupportedException)) + if (tie.InnerException is not NotSupportedException) { throw; } diff --git a/src/System.Management.Automation/engine/parser/Compiler.cs b/src/System.Management.Automation/engine/parser/Compiler.cs index e77097f2088..c2a4bb5f168 100644 --- a/src/System.Management.Automation/engine/parser/Compiler.cs +++ b/src/System.Management.Automation/engine/parser/Compiler.cs @@ -3683,7 +3683,7 @@ public object VisitPipeline(PipelineAst pipelineAst) var temps = new List(); var exprs = new List(); - if (!(pipelineAst.Parent is AssignmentStatementAst || pipelineAst.Parent is ParenExpressionAst)) + if (pipelineAst.Parent is not AssignmentStatementAst && pipelineAst.Parent is not ParenExpressionAst) { // If the parent is an assignment, we've already added a sequence point, don't add another. exprs.Add(UpdatePosition(pipelineAst)); diff --git a/src/System.Management.Automation/engine/parser/Parser.cs b/src/System.Management.Automation/engine/parser/Parser.cs index 89145011523..e3245e91564 100644 --- a/src/System.Management.Automation/engine/parser/Parser.cs +++ b/src/System.Management.Automation/engine/parser/Parser.cs @@ -2423,7 +2423,7 @@ private StatementAst IfStatementRule(Token ifToken) UngetToken(rParen); // Don't bother reporting this error if we already reported an empty condition error. - if (!(condition is ErrorStatementAst)) + if (condition is not ErrorStatementAst) { ReportIncompleteInput(rParen.Extent, nameof(ParserStrings.MissingEndParenthesisAfterStatement), @@ -3611,7 +3611,7 @@ private StatementAst WhileStatementRule(LabelToken labelToken, Token whileToken) // so stop parsing the statement and try parsing something else if possible. UngetToken(rParen); - if (!(condition is ErrorStatementAst)) + if (condition is not ErrorStatementAst) { ReportIncompleteInput(After(condition), nameof(ParserStrings.MissingEndParenthesisAfterStatement), @@ -4966,7 +4966,7 @@ private StatementAst UsingStatementRule(Token usingToken) { htAst = (HashtableAst)aliasAst; } - else if (!(aliasAst is StringConstantExpressionAst)) + else if (aliasAst is not StringConstantExpressionAst) { return new ErrorStatementAst(ExtentOf(usingToken, aliasAst), new Ast[] { itemAst, aliasAst }); } @@ -6703,7 +6703,7 @@ private ExpressionAst ExpressionRule(bool endNumberOnTernaryOpChars = false) UngetToken(token); // Don't bother reporting this error if we already reported an empty 'IfTrue' operand error. - if (!(ifTrue is ErrorExpressionAst)) + if (ifTrue is not ErrorExpressionAst) { componentAsts.Add(ifTrue); ReportIncompleteInput( @@ -7852,7 +7852,7 @@ private ExpressionAst ElementAccessRule(ExpressionAst primaryExpression, Token l UngetToken(rBracket); // Skip reporting the error if we've already reported a missing index. - if (!(indexExpr is ErrorExpressionAst)) + if (indexExpr is not ErrorExpressionAst) { ReportIncompleteInput(After(indexExpr), nameof(ParserStrings.MissingEndSquareBracket), diff --git a/src/System.Management.Automation/engine/parser/SemanticChecks.cs b/src/System.Management.Automation/engine/parser/SemanticChecks.cs index f681a30d070..f46b366785b 100644 --- a/src/System.Management.Automation/engine/parser/SemanticChecks.cs +++ b/src/System.Management.Automation/engine/parser/SemanticChecks.cs @@ -761,7 +761,7 @@ private void CheckAssignmentTarget(ExpressionAst ast, bool simpleAssignment, Act CheckAssignmentTarget(expr, simpleAssignment, reportError); } } - else if (!(ast is ISupportsAssignment)) + else if (ast is not ISupportsAssignment) { errorAst = ast; } @@ -907,7 +907,7 @@ public override AstVisitAction VisitConvertExpression(ConvertExpressionAst conve { if (convertExpressionAst.Type.TypeName.FullName.Equals(LanguagePrimitives.OrderedAttribute, StringComparison.OrdinalIgnoreCase)) { - if (!(convertExpressionAst.Child is HashtableAst)) + if (convertExpressionAst.Child is not HashtableAst) { // We allow the ordered attribute only on hashliteral node. // This check covers the following scenario @@ -1182,7 +1182,7 @@ public override AstVisitAction VisitInvokeMemberExpression(InvokeMemberExpressio private void CheckMemberAccess(MemberExpressionAst ast) { // If the member access is not constant, it may be considered suspicious - if (!(ast.Member is ConstantExpressionAst)) + if (ast.Member is not ConstantExpressionAst) { MarkAstParentsAsSuspicious(ast); } diff --git a/src/System.Management.Automation/engine/parser/SymbolResolver.cs b/src/System.Management.Automation/engine/parser/SymbolResolver.cs index 42091ba2e7b..603ae539cb1 100644 --- a/src/System.Management.Automation/engine/parser/SymbolResolver.cs +++ b/src/System.Management.Automation/engine/parser/SymbolResolver.cs @@ -353,7 +353,7 @@ public override AstVisitAction VisitScriptBlockExpression(ScriptBlockExpressionA public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst functionDefinitionAst) { - if (!(functionDefinitionAst.Parent is FunctionMemberAst)) + if (functionDefinitionAst.Parent is not FunctionMemberAst) { _symbolTable.EnterScope(functionDefinitionAst.Body, ScopeType.Function); } @@ -736,7 +736,7 @@ internal class SymbolResolvePostActionVisitor : DefaultCustomAstVisitor2 public override object VisitFunctionDefinition(FunctionDefinitionAst functionDefinitionAst) { - if (!(functionDefinitionAst.Parent is FunctionMemberAst)) + if (functionDefinitionAst.Parent is not FunctionMemberAst) { _symbolResolver._symbolTable.LeaveScope(); } diff --git a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs index 77efa843f28..59cf5348cc8 100644 --- a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs +++ b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs @@ -2416,7 +2416,7 @@ public static bool AstAssignsToSameVariable(this VariableExpressionAst variableA lhs = convertExpr.Child; } - if (!(lhs is VariableExpressionAst varExpr)) + if (lhs is not VariableExpressionAst varExpr) { return false; } diff --git a/src/System.Management.Automation/engine/parser/tokenizer.cs b/src/System.Management.Automation/engine/parser/tokenizer.cs index 244930b4b21..5fdd4ac4633 100644 --- a/src/System.Management.Automation/engine/parser/tokenizer.cs +++ b/src/System.Management.Automation/engine/parser/tokenizer.cs @@ -2056,7 +2056,7 @@ private void HandleRequiresParameter(CommandParameterAst parameter, return; } - if (!(argumentValue is string)) + if (argumentValue is not string) { ReportError(argumentAst.Extent, nameof(ParserStrings.RequiresInvalidStringArgument), @@ -2069,7 +2069,7 @@ private void HandleRequiresParameter(CommandParameterAst parameter, } else if (PSSnapinToken.StartsWith(parameter.ParameterName, StringComparison.OrdinalIgnoreCase)) { - if (!(argumentValue is string)) + if (argumentValue is not string) { ReportError(argumentAst.Extent, nameof(ParserStrings.RequiresInvalidStringArgument), @@ -2219,7 +2219,7 @@ private void HandleRequiresParameter(CommandParameterAst parameter, private List HandleRequiresAssemblyArgument(Ast argumentAst, object arg, List requiredAssemblies) { - if (!(arg is string)) + if (arg is not string) { ReportError(argumentAst.Extent, nameof(ParserStrings.RequiresInvalidStringArgument), @@ -2242,7 +2242,7 @@ private List HandleRequiresAssemblyArgument(Ast argumentAst, object arg, private List HandleRequiresPSEditionArgument(Ast argumentAst, object arg, ref List requiredEditions) { - if (!(arg is string)) + if (arg is not string) { ReportError(argumentAst.Extent, nameof(ParserStrings.RequiresInvalidStringArgument), diff --git a/src/System.Management.Automation/engine/pipeline.cs b/src/System.Management.Automation/engine/pipeline.cs index 8b1779de882..695a0b38dc8 100644 --- a/src/System.Management.Automation/engine/pipeline.cs +++ b/src/System.Management.Automation/engine/pipeline.cs @@ -1406,8 +1406,8 @@ internal bool RecordFailure(Exception e, InternalCommand command) // Note that the pipeline could have been stopped asynchronously // before hitting the error, therefore we check whether // firstTerminatingError is PipelineStoppedException. - else if ((!(_firstTerminatingError.SourceException is PipelineStoppedException)) - && command != null && command.Context != null) + else if (_firstTerminatingError.SourceException is not PipelineStoppedException + && command?.Context != null) { Exception ex = e; while ((ex is TargetInvocationException || ex is CmdletInvocationException) @@ -1416,7 +1416,7 @@ internal bool RecordFailure(Exception e, InternalCommand command) ex = ex.InnerException; } - if (!(ex is PipelineStoppedException)) + if (ex is not PipelineStoppedException) { string message = StringUtil.Format(PipelineStrings.SecondFailure, _firstTerminatingError.GetType().Name, diff --git a/src/System.Management.Automation/engine/remoting/client/Job.cs b/src/System.Management.Automation/engine/remoting/client/Job.cs index e8453457f47..6db4da1670c 100644 --- a/src/System.Management.Automation/engine/remoting/client/Job.cs +++ b/src/System.Management.Automation/engine/remoting/client/Job.cs @@ -4116,7 +4116,7 @@ private void HandleDebuggerStop(object sender, DebuggerStopEventArgs e) private Pipeline DrainAndBlockRemoteOutput() { // We only do this for remote runspaces. - if (!(_runspace is RemoteRunspace)) { return null; } + if (_runspace is not RemoteRunspace) { return null; } Pipeline runningCmd = _runspace.GetCurrentlyRunningPipeline(); if (runningCmd != null) diff --git a/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs b/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs index 1a9642ca7c2..4f84dfadbdf 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs @@ -1285,7 +1285,7 @@ private static bool VariableDefinitionsTypeValidationCallback(string key, object /// private static bool StringTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path) { - if (!(obj is string)) + if (obj is not string) { cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeString, key, path)); return false; @@ -1315,7 +1315,7 @@ private static bool StringArrayTypeValidationCallback(string key, object obj, PS private static bool BooleanTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path) { - if (!(obj is bool)) + if (obj is not bool) { cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeBoolean, key, path)); return false; @@ -1634,7 +1634,7 @@ internal static void ValidateRoleDefinitions(IDictionary roleDefinitions) { foreach (var roleKey in roleDefinitions.Keys) { - if (!(roleKey is string)) + if (roleKey is not string) { var invalidOperationEx = new PSInvalidOperationException( string.Format(RemotingErrorIdStrings.InvalidRoleKeyType, roleKey.GetType().FullName)); diff --git a/src/System.Management.Automation/engine/runtime/Binding/Binders.cs b/src/System.Management.Automation/engine/runtime/Binding/Binders.cs index a7ace47929d..2f0bc579d19 100644 --- a/src/System.Management.Automation/engine/runtime/Binding/Binders.cs +++ b/src/System.Management.Automation/engine/runtime/Binding/Binders.cs @@ -556,7 +556,7 @@ private DynamicMetaObject NullResult(DynamicMetaObject target) internal static Expression MaybeDebase(DynamicMetaObjectBinder binder, Func generator, DynamicMetaObject target) { - if (!(target.Value is PSObject)) + if (target.Value is not PSObject) { return generator(target.Expression); } @@ -7135,7 +7135,7 @@ internal static Expression InvokeMethod(MethodBase mi, DynamicMetaObject target, { if (parameterType.IsByRef) { - if (!(args[i].Value is PSReference)) + if (args[i].Value is not PSReference) { return Compiler.CreateThrow(typeof(object), typeof(MethodException), new[] { typeof(string), typeof(Exception), typeof(string), typeof(object[]) }, diff --git a/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs b/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs index 819588225ba..a0549a34a6d 100644 --- a/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs +++ b/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs @@ -729,7 +729,7 @@ internal SteppablePipeline GetSteppablePipelineImpl(CommandOrigin commandOrigin, resourceString => { throw PSTraceSource.NewInvalidOperationException(resourceString); }); Diagnostics.Assert(pipelineAst != null, "This should be checked by GetSimplePipeline"); - if (!(pipelineAst.PipelineElements[0] is CommandAst)) + if (pipelineAst.PipelineElements[0] is not CommandAst) { throw PSTraceSource.NewInvalidOperationException(AutomationExceptions.CantConvertEmptyPipeline); } diff --git a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs index 5a452935c6d..edc7e6797de 100644 --- a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs +++ b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs @@ -1917,7 +1917,7 @@ internal static void SetErrorVariables(IScriptExtent extent, RuntimeException rt InterpreterError.UpdateExceptionErrorRecordPosition(rte, extent); ErrorRecord errRec = rte.ErrorRecord.WrapException(rte); - if (!(rte is PipelineStoppedException)) + if (rte is not PipelineStoppedException) { if (outputPipe != null) { diff --git a/src/System.Management.Automation/engine/serialization.cs b/src/System.Management.Automation/engine/serialization.cs index b70c7037c26..de5d107404c 100644 --- a/src/System.Management.Automation/engine/serialization.cs +++ b/src/System.Management.Automation/engine/serialization.cs @@ -3372,7 +3372,7 @@ private CimClass RehydrateCimClass(PSPropertyInfo classMetadataProperty) hashCodeObject = ((PSObject)hashCodeObject).BaseObject; } - if (!(hashCodeObject is int)) + if (hashCodeObject is not int) { return null; } @@ -3426,7 +3426,7 @@ private CimClass RehydrateCimClass(PSPropertyInfo classMetadataProperty) private PSObject RehydrateCimInstance(PSObject deserializedObject) { - if (!(deserializedObject.BaseObject is PSCustomObject)) + if (deserializedObject.BaseObject is not PSCustomObject) { return deserializedObject; } diff --git a/src/System.Management.Automation/help/CommandHelpProvider.cs b/src/System.Management.Automation/help/CommandHelpProvider.cs index 8771c4eced7..c460cc6647b 100644 --- a/src/System.Management.Automation/help/CommandHelpProvider.cs +++ b/src/System.Management.Automation/help/CommandHelpProvider.cs @@ -1178,7 +1178,7 @@ private static bool Match(HelpInfo helpInfo, HelpRequest helpRequest, CommandInf return false; } - if (!(helpInfo is BaseCommandHelpInfo)) + if (helpInfo is not BaseCommandHelpInfo) return false; if (!Match(helpInfo.Component, helpRequest.Component)) diff --git a/src/System.Management.Automation/help/HelpSystem.cs b/src/System.Management.Automation/help/HelpSystem.cs index fb92ed1c19c..222bd33330b 100644 --- a/src/System.Management.Automation/help/HelpSystem.cs +++ b/src/System.Management.Automation/help/HelpSystem.cs @@ -372,7 +372,7 @@ internal IEnumerable ExactMatchHelp(HelpRequest helpRequest) // Bug Win7 737383: Win7 RTM shows both function and cmdlet help when there is // function and cmdlet with the same name. So, ignoring the ScriptCommandHelpProvider's // results and going to the CommandHelpProvider for further evaluation. - if (isHelpInfoFound && (!(helpProvider is ScriptCommandHelpProvider))) + if (isHelpInfoFound && helpProvider is not ScriptCommandHelpProvider) { // once helpInfo found from a provider..no need to traverse other providers. yield break; diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index a24b48c0ef3..6c91b806dfa 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -4206,7 +4206,7 @@ private void RemoveFunctionsPSCopyFileFromRemoteSession(System.Management.Automa private bool ValidRemoteSessionForScripting(Runspace runspace) { - if (!(runspace is RemoteRunspace)) + if (runspace is not RemoteRunspace) { return false; }