Skip to content

Commit

Permalink
Use is not syntax where appropriate and remove unnecessary parenthe…
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze authored Jul 31, 2020
1 parent 5abcd58 commit 4597b41
Show file tree
Hide file tree
Showing 42 changed files with 79 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.PowerShell.Security/security/AclCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ private List<CompletionResult> GetResultForIdentifier(CompletionContext completi
}
}
// Continue trying the filename/commandname completion for scenarios like this: $aa[get-<tab>
else if (!(cursorAst is ErrorExpressionAst && cursorAst.Parent is IndexExpressionAst))
else if (cursorAst is not ErrorExpressionAst || cursorAst.Parent is not IndexExpressionAst)
{
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ private static IEnumerable<PSTypeName> 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());
}
Expand Down Expand Up @@ -7140,7 +7140,7 @@ IEnumerable<CompletionResult> IArgumentCompleter.CompleteArgument(
CommandAst commandAst,
IDictionary fakeBoundParameters)
{
if (!(commandAst.Parent is PipelineAst pipelineAst))
if (commandAst.Parent is not PipelineAst pipelineAst)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/System.Management.Automation/engine/LanguagePrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/System.Management.Automation/engine/MshCommandRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/MshMemberInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -552,7 +552,7 @@ private void LookupMember(string name, HashSet<string> visitedAliases, out PSMem
name);
}

if (!(member is PSAliasProperty aliasMember))
if (member is not PSAliasProperty aliasMember)
{
hasCycle = false;
returnedMember = member;
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/TypeTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -539,12 +539,12 @@ public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSH
/// <returns></returns>
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();
}
Expand Down Expand Up @@ -606,4 +606,3 @@ public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable, PowerShel
#endregion V3 Extensions
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/parser/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3683,7 +3683,7 @@ public object VisitPipeline(PipelineAst pipelineAst)
var temps = new List<ParameterExpression>();
var exprs = new List<Expression>();

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));
Expand Down
10 changes: 5 additions & 5 deletions src/System.Management.Automation/engine/parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 });
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down
Loading

0 comments on commit 4597b41

Please sign in to comment.