Enable IDE0075: SimplifyConditionalExpression (#14078)

https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0075
This commit is contained in:
xtqqczze 2020-12-02 03:25:56 +00:00 committed by GitHub
parent 02ae54726e
commit 18717c529b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 40 additions and 50 deletions

View file

@ -952,7 +952,7 @@ dotnet_diagnostic.IDE0073.severity = suggestion
dotnet_diagnostic.IDE0074.severity = warning
# IDE0075: SimplifyConditionalExpression
dotnet_diagnostic.IDE0075.severity = silent
dotnet_diagnostic.IDE0075.severity = warning
# IDE0076: InvalidSuppressMessageAttribute
dotnet_diagnostic.IDE0076.severity = silent

View file

@ -358,7 +358,7 @@ namespace Microsoft.PowerShell.Commands
{
using (StreamReader streamReader = PathUtils.OpenStreamReader(this, this.Path, Encoding, _isLiteralPath))
{
isCsvFileEmpty = streamReader.Peek() == -1 ? true : false;
isCsvFileEmpty = streamReader.Peek() == -1;
}
}

View file

@ -72,7 +72,7 @@ namespace Microsoft.PowerShell.Commands
}
index = 0;
bool addErrorIdentifier = errorRecords.Count > 1 ? true : false;
bool addErrorIdentifier = errorRecords.Count > 1;
foreach (object errorRecord in errorRecords)
{

View file

@ -208,8 +208,7 @@ namespace Microsoft.PowerShell
bool sizeChanged =
(newRegion.GetLength(0) != _progressRegion.GetLength(0))
|| (newRegion.GetLength(1) != _progressRegion.GetLength(1))
? true : false;
|| (newRegion.GetLength(1) != _progressRegion.GetLength(1));
_progressRegion = newRegion;

View file

@ -202,7 +202,7 @@ namespace System.Diagnostics.Eventing
/// </summary>
public bool IsEnabled()
{
return (_enabled != 0) ? true : false;
return _enabled != 0;
}
/// <summary>

View file

@ -1396,7 +1396,7 @@ namespace System.Diagnostics.Eventing.Reader
bool[] array = new bool[val.Count];
for (int i = 0; i < val.Count; i++)
{
bool value = (Marshal.ReadInt32(ptr) != 0) ? true : false;
bool value = Marshal.ReadInt32(ptr) != 0;
array[i] = value;
ptr = new IntPtr((Int64)ptr + 4);
}

View file

@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.MarkdownRender
{
protected override void Write(VT100Renderer renderer, EmphasisInline obj)
{
renderer.Write(renderer.EscapeSequences.FormatEmphasis(obj.FirstChild.ToString(), isBold: obj.DelimiterCount == 2 ? true : false));
renderer.Write(renderer.EscapeSequences.FormatEmphasis(obj.FirstChild.ToString(), isBold: obj.DelimiterCount == 2));
}
}
}

View file

@ -290,7 +290,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
internal bool DeserializeBoolMemberVariable(PSObject so, string property, bool cannotBeNull = true)
{
var val = DeserializeMemberVariable(so, property, typeof(bool), cannotBeNull);
return (val == null) ? false : (bool)val;
return val != null && (bool)val;
}
internal WriteStreamType DeserializeWriteStreamTypeMemberVariable(PSObject so)

View file

@ -116,7 +116,7 @@ namespace System.Management.Automation
/// </summary>
internal bool ArgumentToBeSplatted
{
get { return _argument != null ? _argument.splatted : false; }
get { return _argument != null && _argument.splatted; }
}
/// <summary>

View file

@ -113,9 +113,7 @@ namespace System.Management.Automation
context = LocalPipeline.GetExecutionContextFromTLS();
}
return (context != null)
? context.IsStrictVersion(majorVersion)
: false;
return (context != null) && context.IsStrictVersion(majorVersion);
}
/// <summary>
/// Check to see a specific version of strict mode is enabled. The check is always scoped,
@ -488,7 +486,7 @@ namespace System.Management.Automation
{
get
{
return InitialSessionState != null ? InitialSessionState.UseFullLanguageModeInDebugger : false;
return InitialSessionState != null && InitialSessionState.UseFullLanguageModeInDebugger;
}
}

View file

@ -443,7 +443,7 @@ namespace System.Management.Automation
get
{
var data = GetRequiresData();
return data == null ? false : data.IsElevationRequired;
return data != null && data.IsElevationRequired;
}
}

View file

@ -1632,8 +1632,7 @@ namespace Microsoft.PowerShell.Commands
new ArrayList(Enum.GetValues(parameterType)) : new ArrayList();
returnParameterType.Properties.Add(new PSNoteProperty("EnumValues", enumValues));
bool hasFlagAttribute = (isArray) ?
((parameterType.GetCustomAttributes(typeof(FlagsAttribute), true)).Length > 0) : false;
bool hasFlagAttribute = (isArray) && ((parameterType.GetCustomAttributes(typeof(FlagsAttribute), true)).Length > 0);
returnParameterType.Properties.Add(new PSNoteProperty("HasFlagAttribute", hasFlagAttribute));
// Recurse into array elements.

View file

@ -274,7 +274,7 @@ namespace System.Management.Automation
{
_scriptBlock = base._scriptBlock;
_obsoleteAttribute = _scriptBlock.ObsoleteAttribute;
_runOptimizedCode = _scriptBlock.Compile(optimized: _context._debuggingMode > 0 ? false : UseLocalScope);
_runOptimizedCode = _scriptBlock.Compile(optimized: _context._debuggingMode <= 0 && UseLocalScope);
_localsTuple = _scriptBlock.MakeLocalsTuple(_runOptimizedCode);
if (UseLocalScope)

View file

@ -78,7 +78,7 @@ namespace System.Management.Automation.Internal.Host
public override bool SupportsVirtualTerminal
{
get { return (_externalUI != null) ? _externalUI.SupportsVirtualTerminal : false; }
get { return _externalUI != null && _externalUI.SupportsVirtualTerminal; }
}
/// <summary>

View file

@ -5546,7 +5546,7 @@ namespace System.Management.Automation
LocalPipeline localPipeline = new LocalPipeline(
lrs,
_shell.Commands.Commands,
((_settings != null) && (_settings.AddToHistory)) ? true : false,
(_settings != null && _settings.AddToHistory),
_shell.IsNested,
_inputStream,
_outputStream,

View file

@ -3449,7 +3449,7 @@ namespace System.Management.Automation.Language
if (ReturnType == null)
return true;
var typeName = ReturnType.TypeName as TypeName;
return typeName == null ? false : typeName.IsType(typeof(void));
return typeName != null && typeName.IsType(typeof(void));
}
internal Type GetReturnType()

View file

@ -98,8 +98,7 @@ namespace System.Management.Automation.Remoting
if (hostPrivateData != null)
{
PSNoteProperty allowSetShouldExit = hostPrivateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty;
hostAllowSetShouldExit = (allowSetShouldExit != null && allowSetShouldExit.Value is bool) ?
(bool)allowSetShouldExit.Value : false;
hostAllowSetShouldExit = allowSetShouldExit != null && allowSetShouldExit.Value is bool && (bool)allowSetShouldExit.Value;
}
}

View file

@ -2968,7 +2968,7 @@ namespace System.Management.Automation
get
{
RemoteRunspace remoteRS = Runspace as RemoteRunspace;
return (remoteRS != null) ? remoteRS.CanDisconnect : false;
return remoteRS != null && remoteRS.CanDisconnect;
}
}

View file

@ -1426,8 +1426,7 @@ namespace System.Management.Automation.Runspaces.Internal
string compressionModeString = pspCompressionMode.Value as string;
if (compressionModeString != null)
{
wsmanConnectionInfo.UseCompression = compressionModeString.Equals("NoCompression", StringComparison.OrdinalIgnoreCase)
? false : true;
wsmanConnectionInfo.UseCompression = !compressionModeString.Equals("NoCompression", StringComparison.OrdinalIgnoreCase);
}
}
@ -1436,8 +1435,7 @@ namespace System.Management.Automation.Runspaces.Internal
string encodingString = pspEncoding.Value as string;
if (encodingString != null)
{
wsmanConnectionInfo.UseUTF16 = encodingString.Equals("UTF16", StringComparison.OrdinalIgnoreCase)
? true : false;
wsmanConnectionInfo.UseUTF16 = encodingString.Equals("UTF16", StringComparison.OrdinalIgnoreCase);
}
}
@ -1446,8 +1444,7 @@ namespace System.Management.Automation.Runspaces.Internal
string machineProfileLoadedString = pspProfile.Value as string;
if (machineProfileLoadedString != null)
{
wsmanConnectionInfo.NoMachineProfile = machineProfileLoadedString.Equals("Yes", StringComparison.OrdinalIgnoreCase)
? false : true;
wsmanConnectionInfo.NoMachineProfile = !machineProfileLoadedString.Equals("Yes", StringComparison.OrdinalIgnoreCase);
}
}

View file

@ -233,7 +233,7 @@ namespace System.Management.Automation.Internal
// Find out if this is an invoke and disconnect operation and if so whether the endpoint
// supports disconnect. Throw exception if disconnect is not supported.
bool invokeAndDisconnect = (shell.Settings != null) ? shell.Settings.InvokeAndDisconnect : false;
bool invokeAndDisconnect = shell.Settings != null && shell.Settings.InvokeAndDisconnect;
if (invokeAndDisconnect && !EndpointSupportsDisconnect)
{
throw new PSRemotingDataStructureException(RemotingErrorIdStrings.EndpointDoesNotSupportDisconnect);
@ -938,7 +938,7 @@ namespace System.Management.Automation.Internal
get
{
WSManClientSessionTransportManager wsmanTransportManager = _transportManager as WSManClientSessionTransportManager;
return (wsmanTransportManager != null) ? wsmanTransportManager.SupportsDisconnect : false;
return wsmanTransportManager != null && wsmanTransportManager.SupportsDisconnect;
}
}

View file

@ -93,7 +93,7 @@ namespace System.Management.Automation.Remoting
// and if we are not in a loopback configuration mode, in which case we always force remote script commands
// to be parsed and evaluated on the remote session (not in the current local session).
RemoteRunspace remoteRunspace = _runspaceRef.Value as RemoteRunspace;
bool isConfiguredLoopback = (remoteRunspace != null) ? remoteRunspace.IsConfiguredLoopBack : false;
bool isConfiguredLoopback = remoteRunspace != null && remoteRunspace.IsConfiguredLoopBack;
bool isTrustedInput = !isConfiguredLoopback && (localRunspace.ExecutionContext.LanguageMode == PSLanguageMode.FullLanguage);
// Create PowerShell from ScriptBlock.

View file

@ -3003,9 +3003,9 @@ namespace Microsoft.PowerShell.Commands
var matchingRunspaceInfos = remoteRunspaceInfos
.Where<PSSession>(session => (supportWildChar ? inputNamePattern.IsMatch(session.VMName)
: inputName.Equals(session.ContainerId)) &&
((sessionNamePattern == null) ? true : sessionNamePattern.IsMatch(session.Name)) &&
(sessionNamePattern == null || sessionNamePattern.IsMatch(session.Name)) &&
QueryRunspaces.TestRunspaceState(session.Runspace, filterState) &&
((configurationNamePattern == null) ? true : configurationNamePattern.IsMatch(session.ConfigurationName)) &&
(configurationNamePattern == null || configurationNamePattern.IsMatch(session.ConfigurationName)) &&
(session.ComputerType == computerType))
.ToList<PSSession>();
@ -3063,7 +3063,7 @@ namespace Microsoft.PowerShell.Commands
: inputName.Equals(session.ContainerId)) &&
sessionInstanceId.Equals(session.InstanceId) &&
QueryRunspaces.TestRunspaceState(session.Runspace, filterState) &&
((configurationNamePattern == null) ? true : configurationNamePattern.IsMatch(session.ConfigurationName)) &&
(configurationNamePattern == null || configurationNamePattern.IsMatch(session.ConfigurationName)) &&
(session.ComputerType == computerType))
.ToList<PSSession>();
@ -3106,9 +3106,9 @@ namespace Microsoft.PowerShell.Commands
var matchingRunspaceInfos = remoteRunspaceInfos
.Where<PSSession>(session => vmId.Equals(session.VMId) &&
((sessionNamePattern == null) ? true : sessionNamePattern.IsMatch(session.Name)) &&
(sessionNamePattern == null || sessionNamePattern.IsMatch(session.Name)) &&
QueryRunspaces.TestRunspaceState(session.Runspace, filterState) &&
((configurationNamePattern == null) ? true : configurationNamePattern.IsMatch(session.ConfigurationName)) &&
(configurationNamePattern == null || configurationNamePattern.IsMatch(session.ConfigurationName)) &&
(session.ComputerType == TargetMachineType.VirtualMachine))
.ToList<PSSession>();
@ -3143,7 +3143,7 @@ namespace Microsoft.PowerShell.Commands
.Where<PSSession>(session => vmId.Equals(session.VMId) &&
sessionInstanceId.Equals(session.InstanceId) &&
QueryRunspaces.TestRunspaceState(session.Runspace, filterState) &&
((configurationNamePattern == null) ? true : configurationNamePattern.IsMatch(session.ConfigurationName)) &&
(configurationNamePattern == null || configurationNamePattern.IsMatch(session.ConfigurationName)) &&
(session.ComputerType == TargetMachineType.VirtualMachine))
.ToList<PSSession>();

View file

@ -661,7 +661,7 @@ namespace Microsoft.PowerShell.Commands
if (originalWSManConnectionInfo != null)
{
newWSManConnectionInfo = originalWSManConnectionInfo.Copy();
newWSManConnectionInfo.EnableNetworkAccess = (newWSManConnectionInfo.EnableNetworkAccess || EnableNetworkAccess) ? true : false;
newWSManConnectionInfo.EnableNetworkAccess = newWSManConnectionInfo.EnableNetworkAccess || EnableNetworkAccess;
newConnectionInfo = newWSManConnectionInfo;
}
else

View file

@ -105,7 +105,7 @@ namespace System.Management.Automation.Remoting
ObjectId = objectId;
FragmentId = fragmentId;
IsStartFragment = (fragmentId == 0) ? true : false;
IsStartFragment = fragmentId == 0;
IsEndFragment = isEndFragment;
_blob = blob;

View file

@ -1925,7 +1925,7 @@ namespace System.Management.Automation.Remoting.Client
}
// check if the session supports disconnect
sessionTM.SupportsDisconnect = ((flags & (int)WSManNativeApi.WSManCallbackFlags.WSMAN_FLAG_CALLBACK_SHELL_SUPPORTS_DISCONNECT) != 0) ? true : false;
sessionTM.SupportsDisconnect = (flags & (int)WSManNativeApi.WSManCallbackFlags.WSMAN_FLAG_CALLBACK_SHELL_SUPPORTS_DISCONNECT) != 0;
// openContent is used by redirection ie., while redirecting to
// a new machine.. this is not needed anymore as the connection

View file

@ -335,7 +335,7 @@ namespace System.Management.Automation.Remoting
// PSEdit support. Existence of RemoteSessionOpenFileEvent event indicates host supports PSEdit
_hostSupportsPSEdit = false;
PSEventManager localEventManager = Runspace?.Events;
_hostSupportsPSEdit = (localEventManager != null) ? localEventManager.GetEventSubscribers(HostUtilities.RemoteSessionOpenFileEvent).GetEnumerator().MoveNext() : false;
_hostSupportsPSEdit = localEventManager != null && localEventManager.GetEventSubscribers(HostUtilities.RemoteSessionOpenFileEvent).GetEnumerator().MoveNext();
if (_hostSupportsPSEdit)
{
AddPSEditForRunspace(remoteRunspace);

View file

@ -1486,9 +1486,7 @@ namespace System.Management.Automation
Breakpoint breakpoint = serverRemoteDebugger.GetBreakpoint(breakpointId, runspaceId);
preProcessOutput.Add(
breakpoint == null
? false
: serverRemoteDebugger.RemoveBreakpoint(breakpoint, runspaceId));
breakpoint != null && serverRemoteDebugger.RemoveBreakpoint(breakpoint, runspaceId));
result = PreProcessCommandResult.BreakpointManagement;
}
@ -1628,7 +1626,7 @@ namespace System.Management.Automation
pump = null;
}
return (pump != null) ? !(pump.IsBusy) : false;
return (pump != null) && !(pump.IsBusy);
}
}

View file

@ -1004,7 +1004,7 @@ namespace System.Management.Automation
args = Array.Empty<object>();
}
bool runOptimized = context._debuggingMode > 0 ? false : createLocalScope;
bool runOptimized = context._debuggingMode <= 0 && createLocalScope;
var codeToInvoke = GetCodeToInvoke(ref runOptimized, clauseToInvoke);
if (codeToInvoke == null)
{
@ -2207,7 +2207,7 @@ namespace System.Management.Automation
_scriptBlock = scriptBlock;
_useLocalScope = useNewScope;
_fromScriptFile = fromScriptFile;
_runOptimized = _scriptBlock.Compile(optimized: context._debuggingMode > 0 ? false : useNewScope);
_runOptimized = _scriptBlock.Compile(optimized: context._debuggingMode <= 0 && useNewScope);
_localsTuple = _scriptBlock.MakeLocalsTuple(_runOptimized);
_localsTuple.SetAutomaticVariable(AutomaticVariable.PSCmdlet, this, context);
_scriptBlock.SetPSScriptRootAndPSCommandPath(_localsTuple, context);

View file

@ -2019,7 +2019,7 @@ namespace Microsoft.PowerShell.Commands
FileAttributes fileAttributes = fileSystemInfo.Attributes;
bool isReparsePoint = InternalSymbolicLinkLinkCodeMethods.IsReparsePoint(fileSystemInfo);
bool isLink = isReparsePoint || (excludeHardLink ? false : InternalSymbolicLinkLinkCodeMethods.IsHardLink(fileSystemInfo));
bool isLink = isReparsePoint || (!excludeHardLink && InternalSymbolicLinkLinkCodeMethods.IsHardLink(fileSystemInfo));
if (!isLink)
{
// special casing for the common cases - no allocations