Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static bool AreAllItemsOfType<T>(IEnumerable items)

foreach (object item in items)
{
if (!(item is T))
if (item is not T)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private RowDefinition CreateNewRow()
/// <param name="uiControl">Will adding UIControl.</param>
private void AddControlToMainGrid(UIElement uiControl)
{
if (this.firstFocusableElement == null && !(uiControl is Label))
if (this.firstFocusableElement == null && uiControl is not Label)
{
this.firstFocusableElement = uiControl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected override void ProcessRecord()
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ private void AddMultipartContent(object fieldName, object fieldValue, MultipartF
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ internal static void RemoveListenersByName(
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ private void DoRunspaceInitialization(bool skipProfiles, string initialCommand,

// 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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/System.Management.Automation/DscSupport/CimDSCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public static object ConvertCimInstanceToObject(Type targetType, CimInstance ins
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private bool LoadMainControlDependentData(List<XmlNode> unprocessedNodes, ViewDe
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2071,22 +2071,22 @@ private void Write15_PropertyMetadata(string n, string ns, global::Microsoft.Pow
{
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ internal List<CompletionResult> GetResultHelper(CompletionContext completionCont
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=<tab>' if incomplete parsing of the assignment.
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5050,7 +5050,7 @@ internal static List<CompletionResult> CompleteMember(CompletionContext context,
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;
Expand Down Expand Up @@ -6567,7 +6567,7 @@ internal static void CompleteMemberHelper(
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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ internal override void ProcessRecord()
// 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ internal virtual void DoBegin()
{
SetCurrentScopeToExecutionScope();

if (Context._debuggingMode > 0 && !(Command is PSScriptCmdlet))
if (Context._debuggingMode > 0 && Command is not PSScriptCmdlet)
{
Context.Debugger.CheckCommand(this.Command.MyInvocation);
}
Expand Down Expand Up @@ -896,7 +896,7 @@ internal void ManageScriptException(RuntimeException e)

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ internal void ResetRedirection()
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;
Expand Down
4 changes: 3 additions & 1 deletion src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,9 @@ private bool IsCommandMatch(ref CommandInfo current, out bool isDuplicate)
}
}

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ private void MethodCallWithArguments()
_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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal Collection<CommandParameterInternal> BindParameters(Collection<CommandP
// 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ internal void CaptureLocals()
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
Expand Down
5 changes: 4 additions & 1 deletion src/System.Management.Automation/engine/MshCommandRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,10 @@ public Exception ManageException(Exception e)
// 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
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/MshObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ public override IEnumerable<string> GetDynamicMemberNames()
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)
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/Pipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ internal void AddItems(object objects)
// 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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/System.Management.Automation/engine/ScopedItemSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ protected override bool GetScopeItem(
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;
Expand Down Expand Up @@ -328,7 +328,7 @@ protected override bool GetScopeItem(
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;
Expand Down Expand Up @@ -470,7 +470,7 @@ protected override bool GetScopeItem(
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public bool RunspaceIsRemote
{
get
{
return !(this is LocalRunspace || ConnectionInfo == null);
return this is not LocalRunspace && ConnectionInfo != null;
}
}

Expand Down Expand Up @@ -943,7 +943,8 @@ internal void UpdateRunspaceAvailability(PipelineState pipelineState, bool raise
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class InternalHost : PSHost, IHostSupportsInteractiveSession
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");

Expand Down
Loading