Skip to content

Commit 7af4679

Browse files
authored
Use compound assignment in Microsoft.PowerShell.ConsoleHost/Security (#17723)
1 parent 8f6b758 commit 7af4679

File tree

6 files changed

+16
-40
lines changed

6 files changed

+16
-40
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,10 +1732,7 @@ internal static void ReadConsoleOutput
17321732
if (origin.X + (contentsRegion.Right - contentsRegion.Left) + 1 < bufferInfo.BufferSize.X &&
17331733
ShouldCheck(contentsRegion.Right, contents, contentsRegion))
17341734
{
1735-
if (cellArray == null)
1736-
{
1737-
cellArray = new BufferCell[cellArrayRegion.Bottom + 1, 2];
1738-
}
1735+
cellArray ??= new BufferCell[cellArrayRegion.Bottom + 1, 2];
17391736

17401737
checkOrigin = new Coordinates(origin.X +
17411738
(contentsRegion.Right - contentsRegion.Left), origin.Y);

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,14 +1388,11 @@ internal WrappedSerializer OutputSerializer
13881388
{
13891389
get
13901390
{
1391-
if (_outputSerializer == null)
1392-
{
1393-
_outputSerializer =
1394-
new WrappedSerializer(
1395-
OutputFormat,
1396-
"Output",
1397-
Console.IsOutputRedirected ? Console.Out : ConsoleTextWriter);
1398-
}
1391+
_outputSerializer ??=
1392+
new WrappedSerializer(
1393+
OutputFormat,
1394+
"Output",
1395+
Console.IsOutputRedirected ? Console.Out : ConsoleTextWriter);
13991396

14001397
return _outputSerializer;
14011398
}
@@ -1405,14 +1402,11 @@ internal WrappedSerializer ErrorSerializer
14051402
{
14061403
get
14071404
{
1408-
if (_errorSerializer == null)
1409-
{
1410-
_errorSerializer =
1411-
new WrappedSerializer(
1412-
ErrorFormat,
1413-
"Error",
1414-
Console.IsErrorRedirected ? Console.Error : ConsoleTextWriter);
1415-
}
1405+
_errorSerializer ??=
1406+
new WrappedSerializer(
1407+
ErrorFormat,
1408+
"Error",
1409+
Console.IsErrorRedirected ? Console.Error : ConsoleTextWriter);
14161410

14171411
return _errorSerializer;
14181412
}
@@ -2533,10 +2527,7 @@ internal void Run(bool inputLoopIsNested)
25332527
prompt = EvaluateDebugPrompt();
25342528
}
25352529

2536-
if (prompt == null)
2537-
{
2538-
prompt = EvaluatePrompt();
2539-
}
2530+
prompt ??= EvaluatePrompt();
25402531
}
25412532

25422533
ui.Write(prompt);

src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ private void AsyncPipelineFailureHandler(Exception ex)
116116
er = new ErrorRecord(er, ex);
117117
}
118118

119-
if (er == null)
120-
{
121-
er = new ErrorRecord(ex, "ConsoleHostAsyncPipelineFailure", ErrorCategory.NotSpecified, null);
122-
}
119+
er ??= new ErrorRecord(ex, "ConsoleHostAsyncPipelineFailure", ErrorCategory.NotSpecified, null);
123120

124121
_parent.ErrorSerializer.Serialize(er);
125122
}

src/Microsoft.PowerShell.ConsoleHost/host/msh/PendingProgress.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ class PendingProgress
119119
ProgressNode parentNode = FindNodeById(newNode.SourceId, newNode.ParentActivityId);
120120
if (parentNode != null)
121121
{
122-
if (parentNode.Children == null)
123-
{
124-
parentNode.Children = new ArrayList();
125-
}
122+
parentNode.Children ??= new ArrayList();
126123

127124
AddNode(parentNode.Children, newNode);
128125
break;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,10 +2546,7 @@ private X509NativeStore GetStore(string storePath,
25462546
}
25472547
}
25482548

2549-
if (s_storeCache == null)
2550-
{
2551-
s_storeCache = new X509NativeStore(storeLocation, storeName);
2552-
}
2549+
s_storeCache ??= new X509NativeStore(storeLocation, storeName);
25532550

25542551
return s_storeCache;
25552552
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,7 @@ public string TimestampServer
374374

375375
set
376376
{
377-
if (value == null)
378-
{
379-
value = string.Empty;
380-
}
377+
value ??= string.Empty;
381378

382379
_timestampServer = value;
383380
}

0 commit comments

Comments
 (0)