Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private void CreateFileStream()
{
using (StreamReader streamReader = PathUtils.OpenStreamReader(this, this.Path, Encoding, _isLiteralPath))
{
isCsvFileEmpty = streamReader.Peek() == -1 ? true : false;
isCsvFileEmpty = streamReader.Peek() == -1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected override void ProcessRecord()
}

index = 0;
bool addErrorIdentifier = errorRecords.Count > 1 ? true : false;
bool addErrorIdentifier = errorRecords.Count > 1;

foreach (object errorRecord in errorRecords)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ class ProgressPane

bool sizeChanged =
(newRegion.GetLength(0) != _progressRegion.GetLength(0))
|| (newRegion.GetLength(1) != _progressRegion.GetLength(1))
? true : false;
|| (newRegion.GetLength(1) != _progressRegion.GetLength(1));

_progressRegion = newRegion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ [In] void* callbackContext
/// </summary>
public bool IsEnabled()
{
return (_enabled != 0) ? true : false;
return _enabled != 0;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ public static Array ConvertToBoolArray(UnsafeNativeMethods.EvtVariant val)
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class EmphasisInlineRenderer : VT100ObjectRenderer<EmphasisInline>
{
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ internal int DeserializeIntMemberVariable(PSObject so, string property)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal object ArgumentValue
/// </summary>
internal bool ArgumentToBeSplatted
{
get { return _argument != null ? _argument.splatted : false; }
get { return _argument != null && _argument.splatted; }
}

/// <summary>
Expand Down
6 changes: 2 additions & 4 deletions src/System.Management.Automation/engine/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ internal static bool IsStrictVersion(ExecutionContext context, int majorVersion)
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,
Expand Down Expand Up @@ -488,7 +486,7 @@ internal bool UseFullLanguageModeInDebugger
{
get
{
return InitialSessionState != null ? InitialSessionState.UseFullLanguageModeInDebugger : false;
return InitialSessionState != null && InitialSessionState.UseFullLanguageModeInDebugger;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ internal bool RequiresElevation
get
{
var data = GetRequiresData();
return data == null ? false : data.IsElevationRequired;
return data != null && data.IsElevationRequired;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,8 +1632,7 @@ private static PSObject GetParameterType(Type parameterType)
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void Init()
{
_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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override

public override bool SupportsVirtualTerminal
{
get { return (_externalUI != null) ? _externalUI.SupportsVirtualTerminal : false; }
get { return _externalUI != null && _externalUI.SupportsVirtualTerminal; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5546,7 +5546,7 @@ internal bool ConstructPipelineAndDoWork(Runspace rs, bool performSyncInvoke)
LocalPipeline localPipeline = new LocalPipeline(
lrs,
_shell.Commands.Commands,
((_settings != null) && (_settings.AddToHistory)) ? true : false,
(_settings != null && _settings.AddToHistory),
_shell.IsNested,
_inputStream,
_outputStream,
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/parser/ast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3449,7 +3449,7 @@ internal bool IsReturnTypeVoid()
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ internal static void Dispatch(
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,7 @@ internal override bool CanDisconnect
get
{
RemoteRunspace remoteRS = Runspace as RemoteRunspace;
return (remoteRS != null) ? remoteRS.CanDisconnect : false;
return remoteRS != null && remoteRS.CanDisconnect;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1426,8 +1426,7 @@ private static void UpdateWSManConnectionInfo(
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);
}
}

Expand All @@ -1436,8 +1435,7 @@ private static void UpdateWSManConnectionInfo(
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);
}
}

Expand All @@ -1446,8 +1444,7 @@ private static void UpdateWSManConnectionInfo(
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ internal void CreatePowerShellOnServerAndInvoke(ClientRemotePowerShell shell)

// 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);
Expand Down Expand Up @@ -938,7 +938,7 @@ internal bool EndpointSupportsDisconnect
get
{
WSManClientSessionTransportManager wsmanTransportManager = _transportManager as WSManClientSessionTransportManager;
return (wsmanTransportManager != null) ? wsmanTransportManager.SupportsDisconnect : false;
return wsmanTransportManager != null && wsmanTransportManager.SupportsDisconnect;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private PSCommand ParsePsCommandUsingScriptBlock(string line, bool? useLocalScop
// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3003,9 +3003,9 @@ private Dictionary<Guid, PSSession> GetMatchingRunspacesByVMNameContainerId(bool
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>();

Expand Down Expand Up @@ -3063,7 +3063,7 @@ private Dictionary<Guid, PSSession> GetMatchingRunspacesByVMNameContainerIdSessi
: 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>();

Expand Down Expand Up @@ -3106,9 +3106,9 @@ private Dictionary<Guid, PSSession> GetMatchingRunspacesByVMId(bool writeobject,

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>();

Expand Down Expand Up @@ -3143,7 +3143,7 @@ private Dictionary<Guid, PSSession> GetMatchingRunspacesByVMIdSessionInstanceId(
.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>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ private List<RemoteRunspace> CreateRunspacesWhenRunspaceParameterSpecified()
if (originalWSManConnectionInfo != null)
{
newWSManConnectionInfo = originalWSManConnectionInfo.Copy();
newWSManConnectionInfo.EnableNetworkAccess = (newWSManConnectionInfo.EnableNetworkAccess || EnableNetworkAccess) ? true : false;
newWSManConnectionInfo.EnableNetworkAccess = newWSManConnectionInfo.EnableNetworkAccess || EnableNetworkAccess;
newConnectionInfo = newWSManConnectionInfo;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal FragmentedRemoteObject(byte[] blob, long objectId, long fragmentId,
ObjectId = objectId;
FragmentId = fragmentId;

IsStartFragment = (fragmentId == 0) ? true : false;
IsStartFragment = fragmentId == 0;
IsEndFragment = isEndFragment;

_blob = blob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ private static void OnCreateSessionCallback(IntPtr operationContext,
}

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public override void PushRunspace(Runspace runspace)
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,9 +1486,7 @@ private static PreProcessCommandResult PreProcessDebuggerCommand(

Breakpoint breakpoint = serverRemoteDebugger.GetBreakpoint(breakpointId, runspaceId);
preProcessOutput.Add(
breakpoint == null
? false
: serverRemoteDebugger.RemoveBreakpoint(breakpoint, runspaceId));
breakpoint != null && serverRemoteDebugger.RemoveBreakpoint(breakpoint, runspaceId));

result = PreProcessCommandResult.BreakpointManagement;
}
Expand Down Expand Up @@ -1628,7 +1626,7 @@ public bool IsAvailable
pump = null;
}

return (pump != null) ? !(pump.IsBusy) : false;
return (pump != null) && !(pump.IsBusy);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ internal void InvokeWithPipeImpl(
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)
{
Expand Down Expand Up @@ -2207,7 +2207,7 @@ public PSScriptCmdlet(ScriptBlock scriptBlock, bool useNewScope, bool fromScript
_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);
Expand Down
Loading