Use null-coalescing assignment in /System.Management.Automation.utils (#17725)

* Use compound assignment in /System.Management.Automation.utils

* Move comments to please style analyzer
This commit is contained in:
Dmitry Volodin
2022-07-25 09:52:17 -07:00
committed by GitHub
parent 8af18fa4ea
commit c6e3ba841b
13 changed files with 102 additions and 177 deletions
@@ -121,14 +121,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
_errorCategory,
_commandName);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
_errorCategory,
_commandName);
return _errorRecord;
}
@@ -161,14 +161,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
"CmdletInvocationException",
ErrorCategory.NotSpecified,
null);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
"CmdletInvocationException",
ErrorCategory.NotSpecified,
null);
return _errorRecord;
}
@@ -891,14 +888,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
"CallDepthOverflow",
ErrorCategory.InvalidOperation,
CallDepth);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
"CallDepthOverflow",
ErrorCategory.InvalidOperation,
CallDepth);
return _errorRecord;
}
@@ -999,14 +993,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
"CallDepthOverflow",
ErrorCategory.InvalidOperation,
CallDepth);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
"CallDepthOverflow",
ErrorCategory.InvalidOperation,
CallDepth);
return _errorRecord;
}
@@ -121,14 +121,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.InvalidArgument,
null);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.InvalidArgument,
null);
return _errorRecord;
}
@@ -119,14 +119,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.InvalidArgument,
null);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.InvalidArgument,
null);
return _errorRecord;
}
@@ -117,14 +117,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.InvalidArgument,
null);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.InvalidArgument,
null);
return _errorRecord;
}
@@ -115,14 +115,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
_errorCategory,
_target);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
_errorCategory,
_target);
return _errorRecord;
}
@@ -98,14 +98,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.NotImplemented,
null);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.NotImplemented,
null);
return _errorRecord;
}
@@ -98,14 +98,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.NotImplemented,
null);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.NotImplemented,
null);
return _errorRecord;
}
@@ -104,14 +104,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.InvalidOperation,
null);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
ErrorCategory.InvalidOperation,
null);
return _errorRecord;
}
@@ -609,15 +609,12 @@ namespace System.Management.Automation.Internal
lock (_monitorObject)
{
if (_readWaitHandle == null)
{
// Create the handle signaled if there are objects in the stream
// or the stream has been closed. The closed scenario addresses
// Pipeline readers that execute asynchronously. Since the pipeline
// may complete with zero objects before the caller objects this
// handle, it will block indefinitely unless it is set.
_readWaitHandle = new ManualResetEvent(_objects.Count > 0 || !_isOpen);
}
// Create the handle signaled if there are objects in the stream
// or the stream has been closed. The closed scenario addresses
// Pipeline readers that execute asynchronously. Since the pipeline
// may complete with zero objects before the caller objects this
// handle, it will block indefinitely unless it is set.
_readWaitHandle ??= new ManualResetEvent(_objects.Count > 0 || !_isOpen);
handle = _readWaitHandle;
}
@@ -642,10 +639,7 @@ namespace System.Management.Automation.Internal
lock (_monitorObject)
{
if (_writeWaitHandle == null)
{
_writeWaitHandle = new ManualResetEvent(_objects.Count < _capacity || !_isOpen);
}
_writeWaitHandle ??= new ManualResetEvent(_objects.Count < _capacity || !_isOpen);
handle = _writeWaitHandle;
}
@@ -665,17 +659,14 @@ namespace System.Management.Automation.Internal
lock (_monitorObject)
{
if (_reader == null)
{
// Always return an object reader, even if the stream
// is closed. This is to address requesting the object reader
// after calling Pipeline.Execute(). NOTE: If Execute completes
// without writing data to the output queue, the
// stream will be in the EndOfPipeline state because the
// stream is closed and has zero data. Since this is a valid
// and expected execution path, we don't want to throw an exception.
_reader = new ObjectReader(this);
}
// Always return an object reader, even if the stream
// is closed. This is to address requesting the object reader
// after calling Pipeline.Execute(). NOTE: If Execute completes
// without writing data to the output queue, the
// stream will be in the EndOfPipeline state because the
// stream is closed and has zero data. Since this is a valid
// and expected execution path, we don't want to throw an exception.
_reader ??= new ObjectReader(this);
reader = _reader;
}
@@ -695,17 +686,14 @@ namespace System.Management.Automation.Internal
lock (_monitorObject)
{
if (_mshreader == null)
{
// Always return an object reader, even if the stream
// is closed. This is to address requesting the object reader
// after calling Pipeline.Execute(). NOTE: If Execute completes
// without writing data to the output queue, the
// stream will be in the EndOfPipeline state because the
// stream is closed and has zero data. Since this is a valid
// and expected execution path, we don't want to throw an exception.
_mshreader = new PSObjectReader(this);
}
// Always return an object reader, even if the stream
// is closed. This is to address requesting the object reader
// after calling Pipeline.Execute(). NOTE: If Execute completes
// without writing data to the output queue, the
// stream will be in the EndOfPipeline state because the
// stream is closed and has zero data. Since this is a valid
// and expected execution path, we don't want to throw an exception.
_mshreader ??= new PSObjectReader(this);
reader = _mshreader;
}
@@ -726,10 +714,7 @@ namespace System.Management.Automation.Internal
lock (_monitorObject)
{
if (_writer == null)
{
_writer = new ObjectWriter(this) as PipelineWriter;
}
_writer ??= new ObjectWriter(this) as PipelineWriter;
writer = _writer;
}
@@ -1686,10 +1671,7 @@ namespace System.Management.Automation.Internal
{
lock (_syncObject)
{
if (_objectReader == null)
{
_objectReader = new PSDataCollectionReader<T, object>(this);
}
_objectReader ??= new PSDataCollectionReader<T, object>(this);
}
}
@@ -1711,11 +1693,8 @@ namespace System.Management.Automation.Internal
{
lock (_syncObject)
{
if (_objectReaderForPipeline == null)
{
_objectReaderForPipeline =
new PSDataCollectionPipelineReader<T, object>(this, computerName, runspaceId);
}
_objectReaderForPipeline ??=
new PSDataCollectionPipelineReader<T, object>(this, computerName, runspaceId);
}
}
@@ -1733,10 +1712,7 @@ namespace System.Management.Automation.Internal
{
lock (_syncObject)
{
if (_psobjectReader == null)
{
_psobjectReader = new PSDataCollectionReader<T, PSObject>(this);
}
_psobjectReader ??= new PSDataCollectionReader<T, PSObject>(this);
}
}
@@ -1758,11 +1734,8 @@ namespace System.Management.Automation.Internal
{
lock (_syncObject)
{
if (_psobjectReaderForPipeline == null)
{
_psobjectReaderForPipeline =
new PSDataCollectionPipelineReader<T, PSObject>(this, computerName, runspaceId);
}
_psobjectReaderForPipeline ??=
new PSDataCollectionPipelineReader<T, PSObject>(this, computerName, runspaceId);
}
}
@@ -1784,10 +1757,7 @@ namespace System.Management.Automation.Internal
{
lock (_syncObject)
{
if (_writer == null)
{
_writer = new PSDataCollectionWriter<T>(this) as PipelineWriter;
}
_writer ??= new PSDataCollectionWriter<T>(this) as PipelineWriter;
}
}
@@ -212,10 +212,7 @@ namespace System.Management.Automation
_parameterType = parameterType;
_typeSpecified = typeSpecified;
if (errorPosition == null)
{
errorPosition = invocationInfo.ScriptPosition;
}
errorPosition ??= invocationInfo.ScriptPosition;
if (errorPosition != null)
{
@@ -151,14 +151,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
_errorCategory,
_targetObject);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
_errorCategory,
_targetObject);
return _errorRecord;
}
@@ -234,14 +234,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
"ProviderInvocationException",
ErrorCategory.NotSpecified,
null);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
"ProviderInvocationException",
ErrorCategory.NotSpecified,
null);
return _errorRecord;
}
@@ -497,14 +494,11 @@ namespace System.Management.Automation
{
get
{
if (_errorRecord == null)
{
_errorRecord = new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
_errorCategory,
_itemName);
}
_errorRecord ??= new ErrorRecord(
new ParentContainsErrorRecordException(this),
_errorId,
_errorCategory,
_itemName);
return _errorRecord;
}