Enable CA1836: Prefer IsEmpty over Count when available (#13877)
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1836
This commit is contained in:
parent
af8558b065
commit
2c1546cd47
|
@ -319,7 +319,7 @@ dotnet_diagnostic.CA1834.severity = warning
|
|||
dotnet_diagnostic.CA1835.severity = suggestion
|
||||
|
||||
# CA1836: Prefer IsEmpty over Count
|
||||
dotnet_diagnostic.CA1836.severity = suggestion
|
||||
dotnet_diagnostic.CA1836.severity = warning
|
||||
|
||||
# CA1837: Use 'Environment.ProcessId'
|
||||
dotnet_diagnostic.CA1837.severity = suggestion
|
||||
|
|
|
@ -1089,7 +1089,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
WriteError(errorRecord);
|
||||
}
|
||||
|
||||
if (visitor.DuplicateSymbols.Count > 0)
|
||||
if (!visitor.DuplicateSymbols.IsEmpty)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
new InvalidOperationException(AddTypeStrings.CompilerErrors),
|
||||
|
|
|
@ -368,7 +368,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
var errors = new ConcurrentBag<string>();
|
||||
this.Context.TypeTable.Update(type, errors, false);
|
||||
// Write out errors...
|
||||
if (errors.Count > 0)
|
||||
if (!errors.IsEmpty)
|
||||
{
|
||||
foreach (string s in errors)
|
||||
{
|
||||
|
@ -492,7 +492,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
var errors = new ConcurrentBag<string>();
|
||||
this.Context.TypeTable.Update(type, errors, false);
|
||||
// Write out errors...
|
||||
if (errors.Count > 0)
|
||||
if (!errors.IsEmpty)
|
||||
{
|
||||
foreach (string s in errors)
|
||||
{
|
||||
|
@ -862,7 +862,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
Context.InitialSessionState.Types.Add(sste);
|
||||
|
||||
// Write out any errors...
|
||||
if (errors.Count > 0)
|
||||
if (!errors.IsEmpty)
|
||||
{
|
||||
foreach (string s in errors)
|
||||
{
|
||||
|
@ -1219,7 +1219,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
var errors = new ConcurrentBag<string>();
|
||||
Context.TypeTable.Update(type, errors, true);
|
||||
// Write out errors...
|
||||
if (errors.Count > 0)
|
||||
if (!errors.IsEmpty)
|
||||
{
|
||||
foreach (string s in errors)
|
||||
{
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
|||
this.isShared = isShared;
|
||||
|
||||
// check to see if there are any errors loading the format files
|
||||
if (errors.Count > 0)
|
||||
if (!errors.IsEmpty)
|
||||
{
|
||||
throw new FormatTableLoadException(errors);
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
|||
LoadFromFile(filesToLoad, expressionFactory, false, null, null, false, out logEntries);
|
||||
|
||||
// check to see if there are any errors loading the format files
|
||||
if (errors.Count > 0)
|
||||
if (!errors.IsEmpty)
|
||||
{
|
||||
throw new FormatTableLoadException(errors);
|
||||
}
|
||||
|
|
|
@ -3630,7 +3630,7 @@ namespace System.Management.Automation.Runspaces
|
|||
}
|
||||
}
|
||||
|
||||
if (errors.Count > 0)
|
||||
if (!errors.IsEmpty)
|
||||
{
|
||||
var allErrors = new StringBuilder();
|
||||
allErrors.Append('\n');
|
||||
|
@ -3739,7 +3739,7 @@ namespace System.Management.Automation.Runspaces
|
|||
// if this is the case...
|
||||
foreach (PSSnapInTypeAndFormatErrors entry in entries)
|
||||
{
|
||||
if (entry.Errors != null && entry.Errors.Count > 0)
|
||||
if (entry.Errors != null && !entry.Errors.IsEmpty)
|
||||
{
|
||||
foreach (string error in entry.Errors)
|
||||
{
|
||||
|
|
|
@ -3937,7 +3937,7 @@ namespace System.Management.Automation.Runspaces
|
|||
_typeFileList.Add(typefile);
|
||||
}
|
||||
|
||||
if (errors.Count > 0)
|
||||
if (!errors.IsEmpty)
|
||||
{
|
||||
throw new TypeTableLoadException(errors);
|
||||
}
|
||||
|
|
|
@ -1023,7 +1023,7 @@ namespace System.Management.Automation
|
|||
|
||||
internal override bool IsPushed
|
||||
{
|
||||
get { return (_activeDebuggers.Count > 0); }
|
||||
get { return (!_activeDebuggers.IsEmpty); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2000,7 +2000,7 @@ namespace System.Management.Automation
|
|||
|
||||
private void SetPendingBreakpoints(FunctionContext functionContext)
|
||||
{
|
||||
if (_pendingBreakpoints.Count == 0)
|
||||
if (_pendingBreakpoints.IsEmpty)
|
||||
return;
|
||||
|
||||
var newPendingBreakpoints = new Dictionary<int, LineBreakpoint>();
|
||||
|
@ -2133,7 +2133,7 @@ namespace System.Management.Automation
|
|||
{
|
||||
// The debugger can be disbled if there are no breakpoints
|
||||
// left and if we are not currently stepping in the debugger.
|
||||
return _idToBreakpoint.Count == 0 &&
|
||||
return _idToBreakpoint.IsEmpty &&
|
||||
_currentDebuggerAction != DebuggerResumeAction.StepInto &&
|
||||
_currentDebuggerAction != DebuggerResumeAction.StepOver &&
|
||||
_currentDebuggerAction != DebuggerResumeAction.StepOut;
|
||||
|
@ -2244,7 +2244,7 @@ namespace System.Management.Automation
|
|||
|
||||
private void RestoreInternalDebugMode()
|
||||
{
|
||||
InternalDebugMode restoreMode = ((DebugMode != DebugModes.None) && (_idToBreakpoint.Count > 0)) ? InternalDebugMode.Enabled : InternalDebugMode.Disabled;
|
||||
InternalDebugMode restoreMode = ((DebugMode != DebugModes.None) && (!_idToBreakpoint.IsEmpty)) ? InternalDebugMode.Enabled : InternalDebugMode.Disabled;
|
||||
SetInternalDebugMode(restoreMode);
|
||||
}
|
||||
|
||||
|
@ -2421,7 +2421,7 @@ namespace System.Management.Automation
|
|||
{
|
||||
SetInternalDebugMode(InternalDebugMode.Disabled);
|
||||
}
|
||||
else if ((_idToBreakpoint.Count > 0) && (_context._debuggingMode == 0))
|
||||
else if ((!_idToBreakpoint.IsEmpty) && (_context._debuggingMode == 0))
|
||||
{
|
||||
// Set internal debugger to active.
|
||||
SetInternalDebugMode(InternalDebugMode.Enabled);
|
||||
|
@ -3920,7 +3920,7 @@ namespace System.Management.Automation
|
|||
|
||||
Interlocked.CompareExchange(ref _processingRunspaceDebugQueue, 0, 1);
|
||||
|
||||
if (_runspaceDebugQueue.Value.Count > 0)
|
||||
if (!_runspaceDebugQueue.Value.IsEmpty)
|
||||
{
|
||||
StartRunspaceForDebugQueueProcessing();
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ namespace System.Management.Automation.Runspaces
|
|||
ConcurrentBag<string> errors,
|
||||
Category category)
|
||||
{
|
||||
if (errors.Count == 0)
|
||||
if (errors.IsEmpty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue