Skip to content

Commit 4597b41

Browse files
authored
Use is not syntax where appropriate and remove unnecessary parentheses (PowerShell#13323)
1 parent 5abcd58 commit 4597b41

42 files changed

Lines changed: 79 additions & 81 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ protected object GetReferenceOrReferenceArrayObject(object value, ref CimType re
404404
{
405405
return null;
406406
}
407-
else if (!(cimReferenceArray[0] is PSReference))
407+
else if (cimReferenceArray[0] is not PSReference)
408408
{
409409
return null;
410410
}

src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ private static void AddShowComputerNameMarker(object o)
10551055
}
10561056

10571057
PSObject pso = PSObject.AsPSObject(o);
1058-
if (!(pso.BaseObject is CimInstance))
1058+
if (pso.BaseObject is not CimInstance)
10591059
{
10601060
return;
10611061
}
@@ -2086,7 +2086,7 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args)
20862086
{
20872087
DebugHelper.WriteLogEx();
20882088

2089-
if (!(args.Action is CimWriteResultObject))
2089+
if (args.Action is not CimWriteResultObject)
20902090
{
20912091
// allow all other actions
20922092
return true;
@@ -2240,7 +2240,7 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args)
22402240
{
22412241
DebugHelper.WriteLogEx();
22422242

2243-
if (!(args.Action is CimWriteResultObject))
2243+
if (args.Action is not CimWriteResultObject)
22442244
{
22452245
// allow all other actions
22462246
return true;

src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/clientSideQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public bool IsMatch(CimInstance o)
405405

406406
private object ConvertActualValueToExpectedType(object actualPropertyValue, object expectedPropertyValue)
407407
{
408-
if ((actualPropertyValue is string) && (!(expectedPropertyValue is string)))
408+
if (actualPropertyValue is string && expectedPropertyValue is not string)
409409
{
410410
actualPropertyValue = LanguagePrimitives.ConvertTo(actualPropertyValue, expectedPropertyValue.GetType(), CultureInfo.InvariantCulture);
411411
}

src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ internal virtual void PrepareSession()
667667

668668
// null is not valid value for header.
669669
// We silently ignore header if value is null.
670-
if (!(value is null))
670+
if (value is not null)
671671
{
672672
// add the header value (or overwrite it if already present)
673673
WebSession.Headers[key] = value.ToString();

src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceExpressionCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ private static ErrorRecord ConvertToErrorRecord(object obj)
525525
if (mshobj != null)
526526
{
527527
object baseObject = mshobj.BaseObject;
528-
if (!(baseObject is PSCustomObject))
528+
if (baseObject is not PSCustomObject)
529529
{
530530
obj = baseObject;
531531
}

src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public override bool Equals(object obj)
7575
if (obj == null)
7676
return false;
7777

78-
if (!(obj is PropertyKey))
78+
if (obj is not PropertyKey)
7979
return false;
8080

8181
PropertyKey other = (PropertyKey)obj;

src/Microsoft.PowerShell.ScheduledJob/ScheduledJobDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ public void Register()
938938
{ }
939939
}
940940

941-
if (!(ex is ScheduledJobException))
941+
if (ex is not ScheduledJobException)
942942
{
943943
// Wrap in ScheduledJobException type.
944944
string msg = StringUtil.Format(ScheduledJobErrorStrings.ErrorRegisteringDefinitionStore, this.Name);

src/Microsoft.PowerShell.Security/security/AclCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ protected override void ProcessRecord()
783783
{
784784
customDescriptor = PSObject.Base(methodInfo.Invoke());
785785

786-
if (!(customDescriptor is FileSystemSecurity))
786+
if (customDescriptor is not FileSystemSecurity)
787787
{
788788
customDescriptor = new CommonSecurityDescriptor(false, false, customDescriptor.ToString());
789789
}

src/Microsoft.PowerShell.Security/security/CertificateProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ protected override bool ItemExists(string path)
11951195
// If the inner exception is not of that type
11961196
// then we need to rethrow
11971197
//
1198-
if (!(e.InnerException is CertificateProviderItemNotFoundException))
1198+
if (e.InnerException is not CertificateProviderItemNotFoundException)
11991199
{
12001200
throw;
12011201
}

src/System.Management.Automation/FormatAndOutput/out-console/OutConsole.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ protected override void ProcessRecord()
109109
object inputObjectBase = PSObject.Base(InputObject);
110110

111111
// Ignore errors and formatting records, as those can't be captured
112-
if (
113-
(inputObjectBase != null) &&
114-
(!(inputObjectBase is ErrorRecord)) &&
115-
(!inputObjectBase.GetType().FullName.StartsWith(
116-
"Microsoft.PowerShell.Commands.Internal.Format", StringComparison.OrdinalIgnoreCase)))
112+
if (inputObjectBase != null &&
113+
inputObjectBase is not ErrorRecord &&
114+
!inputObjectBase.GetType().FullName.StartsWith(
115+
"Microsoft.PowerShell.Commands.Internal.Format", StringComparison.OrdinalIgnoreCase))
117116
{
118117
_outVarResults.Add(InputObject);
119118
}

0 commit comments

Comments
 (0)