Use null propagation operator in Management and ConsoleHost (#17791)

This commit is contained in:
Frode Flaten authored and GitHub committed 2022-08-01 09:20:44 -07:00
1 parent d204d29035
commit 2d4a6bf475
7 files changed
+27 -108

No files matched your search

@@ -683,10 +683,7 @@ namespace Microsoft.PowerShell.Cmdletization
public override void StopProcessing()
{
Job jobToStop = _parentJob;
if (jobToStop != null)
{
jobToStop.StopJob();
}
jobToStop?.StopJob();
base.StopProcessing();
}
@@ -315,10 +315,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
this.ExceptionSafeWrapper(delegate
{
IObservable<T> observable = this.GetCimOperation();
if (observable != null)
{
observable.Subscribe(this);
}
observable?.Subscribe(this);
});
});
}
@@ -522,10 +519,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
}
CimCustomOptionsDictionary jobSpecificCustomOptions = this.GetJobSpecificCustomOptions();
if (jobSpecificCustomOptions != null)
{
jobSpecificCustomOptions.Apply(operationOptions, CimSensitiveValueConverter);
}
jobSpecificCustomOptions?.Apply(operationOptions, CimSensitiveValueConverter);
return operationOptions;
}
@@ -377,10 +377,7 @@ namespace Microsoft.PowerShell.Commands
{
try
{
if (holder.Writer != null)
{
holder.Writer.Close();
}
holder.Writer?.Close();
}
catch (Exception e) // Catch-all OK. 3rd party callout
{
@@ -414,10 +411,7 @@ namespace Microsoft.PowerShell.Commands
try
{
if (holder.Reader != null)
{
holder.Reader.Close();
}
holder.Reader?.Close();
}
catch (Exception e) // Catch-all OK. 3rd party callout
{
@@ -938,10 +938,7 @@ namespace Microsoft.PowerShell.Commands
{
if (System.Threading.Interlocked.Decrement(ref _numberOfProcessesToWaitFor) == 0)
{
if (_waitHandle != null)
{
_waitHandle.Set();
}
_waitHandle?.Set();
}
}
@@ -1040,13 +1037,8 @@ namespace Microsoft.PowerShell.Commands
/// <summary>
/// StopProcessing.
/// </summary>
protected override void StopProcessing()
{
if (_waitHandle != null)
{
_waitHandle.Set();
}
}
protected override void StopProcessing() => _waitHandle?.Set();
#endregion Overrides
}
@@ -2079,13 +2071,7 @@ namespace Microsoft.PowerShell.Commands
/// <summary>
/// Implements ^c, after creating a process.
/// </summary>
protected override void StopProcessing()
{
if (_waithandle != null)
{
_waithandle.Set();
}
}
protected override void StopProcessing() => _waithandle?.Set();
#endregion
@@ -2116,13 +2102,7 @@ namespace Microsoft.PowerShell.Commands
/// <summary>
/// When Process exits the wait handle is set.
/// </summary>
private void myProcess_Exited(object sender, System.EventArgs e)
{
if (_waithandle != null)
{
_waithandle.Set();
}
}
private void myProcess_Exited(object sender, System.EventArgs e) => _waithandle?.Set();
private string ResolveFilePath(string path)
{
@@ -2221,15 +2201,8 @@ namespace Microsoft.PowerShell.Commands
{
Thread.Sleep(1000);
if (_outputWriter != null)
{
_outputWriter.Dispose();
}
if (_errorWriter != null)
{
_errorWriter.Dispose();
}
_outputWriter?.Dispose();
_errorWriter?.Dispose();
}
private void SetupInputOutputRedirection(Process p)
@@ -189,10 +189,7 @@ namespace Microsoft.PowerShell
if ((s_cpp.ServerMode && s_cpp.NamedPipeServerMode) || (s_cpp.ServerMode && s_cpp.SocketServerMode) || (s_cpp.NamedPipeServerMode && s_cpp.SocketServerMode))
{
s_tracer.TraceError("Conflicting server mode parameters, parameters must be used exclusively.");
if (s_theConsoleHost != null)
{
s_theConsoleHost.ui.WriteErrorLine(ConsoleHostStrings.ConflictingServerModeParameters);
}
s_theConsoleHost?.ui.WriteErrorLine(ConsoleHostStrings.ConflictingServerModeParameters);
return ExitCodeBadCommandLineParameter;
}
@@ -501,10 +498,7 @@ namespace Microsoft.PowerShell
if (runspaceRef != null)
{
var runspace = runspaceRef.Runspace;
if (runspace != null)
{
runspace.Close();
}
runspace?.Close();
}
}
}
@@ -1266,15 +1260,8 @@ namespace Microsoft.PowerShell
StopTranscribing();
}
if (_outputSerializer != null)
{
_outputSerializer.End();
}
if (_errorSerializer != null)
{
_errorSerializer.End();
}
_outputSerializer?.End();
_errorSerializer?.End();
if (_runspaceRef != null)
{
@@ -2233,10 +2220,7 @@ namespace Microsoft.PowerShell
// For remote debugging block data coming from the main (not-nested)
// running command.
baseLoop = InputLoop.GetNonNestedLoop();
if (baseLoop != null)
{
baseLoop.BlockCommandOutput();
}
baseLoop?.BlockCommandOutput();
}
//
@@ -2281,10 +2265,7 @@ namespace Microsoft.PowerShell
finally
{
_debuggerStopEventArgs = null;
if (baseLoop != null)
{
baseLoop.ResumeCommandOutput();
}
baseLoop?.ResumeCommandOutput();
}
}
@@ -2670,10 +2651,7 @@ namespace Microsoft.PowerShell
bht = _parent._breakHandlerThread;
}
if (bht != null)
{
bht.Join();
}
bht?.Join();
// Once the pipeline has been executed, we toss any outstanding progress data and
// take down the display.
@@ -139,20 +139,14 @@ namespace Microsoft.PowerShell
void
PreWrite()
{
if (_progPane != null)
{
_progPane.Hide();
}
_progPane?.Hide();
}
private
void
PostWrite()
{
if (_progPane != null)
{
_progPane.Show();
}
_progPane?.Show();
}
private
@@ -178,20 +172,14 @@ namespace Microsoft.PowerShell
void
PreRead()
{
if (_progPane != null)
{
_progPane.Hide();
}
_progPane?.Hide();
}
private
void
PostRead()
{
if (_progPane != null)
{
_progPane.Show();
}
_progPane?.Show();
}
private
@@ -599,11 +599,9 @@ namespace Microsoft.PowerShell
internal void ResumeCommandOutput()
{
RemotePipeline remotePipeline = _pipeline as RemotePipeline;
if (remotePipeline != null)
{
// Resumes data flow.
remotePipeline.ResumeIncomingData();
}
// Resumes data flow.
remotePipeline?.ResumeIncomingData();
}
/// <summary>
@@ -697,10 +695,7 @@ namespace Microsoft.PowerShell
temp = s_currentExecutor;
}
if (temp != null)
{
temp.Cancel();
}
temp?.Cancel();
}
// These statics are threadsafe, as there can be only one instance of ConsoleHost in a process at a time, and access