diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs index 566ec8929f7..67c1ba31efd 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetChildrenCommand.cs @@ -288,8 +288,7 @@ protected override void ProcessRecord() { CmdletProviderContext currentContext = CmdletProviderContext; - if (_paths == null || - (_paths != null && _paths.Length == 0)) + if (_paths == null || _paths.Length == 0) { _paths = new string[] { String.Empty }; } diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index e16d512b1f1..fb2f92ffff3 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -2362,8 +2362,7 @@ protected override bool ProviderSupportsShouldProcess /// protected override void ProcessRecord() { - if (Path == null || - (Path != null && Path.Length == 0)) + if (Path == null || Path.Length == 0) { Path = new string[] { String.Empty }; } @@ -4533,9 +4532,7 @@ public string[] PSProvider /// protected override void ProcessRecord() { - if (PSProvider == null || - (PSProvider != null && - PSProvider.Length == 0)) + if (PSProvider == null || PSProvider.Length == 0) { // Get all the providers diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs index e8bde3599c2..50554e6b0ae 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetContentCommand.cs @@ -28,8 +28,7 @@ public class SetContentCommand : WriteContentCommandBase /// internal override void BeforeOpenStreams(string[] paths) { - if (paths == null || - (paths != null && paths.Length == 0)) + if (paths == null || paths.Length == 0) { throw PSTraceSource.NewArgumentNullException("paths"); } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index ff713604d3a..0a73bdcac89 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -741,8 +741,7 @@ public override if (((ConsoleControl.InputRecordEventTypes)inputRecords[0].EventType) == ConsoleControl.InputRecordEventTypes.KEY_EVENT) { - Dbg.Assert((inputRecords[0].KeyEvent.KeyDown && inputRecords[0].KeyEvent.RepeatCount != 0) || - !inputRecords[0].KeyEvent.KeyDown, + Dbg.Assert(!inputRecords[0].KeyEvent.KeyDown || inputRecords[0].KeyEvent.RepeatCount != 0, string.Format(CultureInfo.InvariantCulture, "ReadConsoleInput returns a KeyEvent that is KeyDown and RepeatCount 0")); if (inputRecords[0].KeyEvent.RepeatCount == 0) { @@ -867,8 +866,7 @@ public override if (((ConsoleControl.InputRecordEventTypes)inputRecords[i].EventType) == ConsoleControl.InputRecordEventTypes.KEY_EVENT) { - Dbg.Assert((inputRecords[i].KeyEvent.KeyDown && inputRecords[i].KeyEvent.RepeatCount != 0) || - !inputRecords[i].KeyEvent.KeyDown, + Dbg.Assert(!inputRecords[i].KeyEvent.KeyDown || inputRecords[i].KeyEvent.RepeatCount != 0, string.Format(CultureInfo.InvariantCulture, "PeekConsoleInput returns a KeyEvent that is KeyDown and RepeatCount 0")); if (inputRecords[i].KeyEvent.KeyDown && inputRecords[i].KeyEvent.RepeatCount == 0) diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs index 0adbeab0686..668e02a1a82 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/Reader/EventLogReader.cs @@ -305,16 +305,7 @@ public void Seek(SeekOrigin origin, long offset) } else { - //if inside the current buffer, we still cannot read the events, as the handles. - //may have already been closed. - if (_currentIndex + offset >= 0) - { - SeekCommon(offset); - } - else //outside the current buffer - { - SeekCommon(offset); - } + SeekCommon(offset); } return; } diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index a300e55085b..b6faf4aacdf 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -2581,7 +2581,7 @@ private void PutResourceValue(object sessionobj, string ResourceURI, Hashtable v nsmgr.AddNamespace("cfg", uri_schema); string xpath = SetXPathString(ResourceURI); XmlNodeList nodelist = inputxml.SelectNodes(xpath, nsmgr); - if (nodelist.Count == 1 && nodelist != null) + if (nodelist != null && nodelist.Count == 1) { XmlNode node = (XmlNode)nodelist.Item(0); if (node.HasChildNodes) diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index d33423ddf00..7608a1a0c79 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -495,20 +495,7 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, internal string GetXmlNs(string resUri) { - - string tmpNs = null; - - if (resUri.ToLowerInvariant().Contains(URI_IPMI) || (resUri.ToLowerInvariant().Contains(URI_WMI))) - tmpNs = StripParams(resUri); - else - { - //tmpNs = StripParams(resUri) + ".xsd"; - //This was reported by Intel as an interop issue. So now we are not appending a .xsd in the end. - tmpNs = StripParams(resUri); - } - - return (@"xmlns:p=""" + tmpNs + @""""); - + return (@"xmlns:p=""" + StripParams(resUri) + @""""); } internal XmlNode GetXmlNode(string xmlString, string xpathpattern, string xmlnamespace) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs index ead3ac08bb8..a115e568ac2 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs @@ -1182,10 +1182,7 @@ private string FindLastWord(out int replacementIndexOut, out char closingQuote) for (_sentenceIndex = 0; _sentenceIndex < _sentence.Length; ++_sentenceIndex) { - Diagnostics.Assert( - (inSingleQuote && !inDoubleQuote) - || (inDoubleQuote && !inSingleQuote) - || (!inSingleQuote && !inDoubleQuote), + Diagnostics.Assert(!(inSingleQuote && inDoubleQuote), "Can't be in both single and double quotes"); char c = _sentence[_sentenceIndex]; diff --git a/src/System.Management.Automation/engine/CoreAdapter.cs b/src/System.Management.Automation/engine/CoreAdapter.cs index 8de45b9c69e..2f848467763 100644 --- a/src/System.Management.Automation/engine/CoreAdapter.cs +++ b/src/System.Management.Automation/engine/CoreAdapter.cs @@ -862,10 +862,7 @@ private static int CompareOverloadCandidates(OverloadCandidate candidate1, Overl return 0; } } - } - if (betterCount == 0) - { // Apply tie breaking rules, related to expanded parameters if (candidate1.expandedParameters != null && candidate2.expandedParameters != null) { @@ -880,10 +877,8 @@ private static int CompareOverloadCandidates(OverloadCandidate candidate1, Overl { return 1; } - } - if (betterCount == 0) - { + // Apply tie breaking rules, related to specificity of parameters betterCount = CompareTypeSpecificity(candidate1, candidate2); } diff --git a/src/System.Management.Automation/engine/DataStoreAdapter.cs b/src/System.Management.Automation/engine/DataStoreAdapter.cs index 6ababeb0c57..4685a29e3a1 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapter.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapter.cs @@ -804,18 +804,9 @@ public bool Equals(PSDriveInfo drive) Object drive1Object = drive1; Object drive2Object = drive2; - if ((drive1Object == null)) + if (drive1Object == null) { - if (drive2Object == null) - { - // Since both drives are null, they are equal - return false; - } - else - { - // Since drive1 is null it is less than drive2 which is not null - return true; - } + return (drive2Object != null); } else { @@ -856,16 +847,9 @@ public bool Equals(PSDriveInfo drive) if ((drive1Object == null)) { - if (drive2Object == null) - { - // Since both drives are null, they are equal - return false; - } - else - { - // Since drive1 is null it is less than drive2 which is not null - return false; - } + // Since both drives are null, they are equal + // Since drive1 is null it is less than drive2 which is not null + return false; } else { diff --git a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs index a8286ec146d..33cd2e3df78 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs @@ -400,12 +400,6 @@ internal ProviderInfo( throw PSTraceSource.NewArgumentNullException("implementingType"); } - if (String.IsNullOrEmpty(name)) - { - throw PSTraceSource.NewArgumentException("name"); - } - - if (String.IsNullOrEmpty(name)) { throw PSTraceSource.NewArgumentException("name"); diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index cc4ab30645e..3e5e7b9830f 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -3691,7 +3691,7 @@ internal object Convert(object valueToConvert, ExecutionContext ecFromTLS = LocalPipeline.GetExecutionContextFromTLS(); object result = null; - if ((ecFromTLS == null) || (ecFromTLS != null && ecFromTLS.LanguageMode == PSLanguageMode.FullLanguage)) + if (ecFromTLS == null || ecFromTLS.LanguageMode == PSLanguageMode.FullLanguage) { result = _constructor(); var psobject = valueToConvert as PSObject; diff --git a/src/System.Management.Automation/engine/Modules/AnalysisCache.cs b/src/System.Management.Automation/engine/Modules/AnalysisCache.cs index 19809589557..4f01415879e 100644 --- a/src/System.Management.Automation/engine/Modules/AnalysisCache.cs +++ b/src/System.Management.Automation/engine/Modules/AnalysisCache.cs @@ -634,14 +634,14 @@ public void QueueSerialization() // Wait a while before assuming we've finished the updates, // writing the cache out in a timely matter isn't too important // now anyway. - await Task.Delay(10000); + await Task.Delay(10000).ConfigureAwait(false); int counter1, counter2; do { // Check the counter a couple times with a delay, // if it's stable, then proceed with writing. counter1 = _saveCacheToDiskQueued; - await Task.Delay(3000); + await Task.Delay(3000).ConfigureAwait(false); counter2 = _saveCacheToDiskQueued; } while (counter1 != counter2); Serialize(s_cacheStoreLocation); diff --git a/src/System.Management.Automation/engine/SessionStatePublic.cs b/src/System.Management.Automation/engine/SessionStatePublic.cs index e1bf6cbd26c..0fa35a25075 100644 --- a/src/System.Management.Automation/engine/SessionStatePublic.cs +++ b/src/System.Management.Automation/engine/SessionStatePublic.cs @@ -208,9 +208,7 @@ public static void ThrowIfNotVisible(CommandOrigin origin, object valueToCheck) CommandInfo cinfo = valueToCheck as CommandInfo; if (cinfo != null) { - string commandName = null; - if (cinfo != null) - commandName = cinfo.Name; + string commandName = cinfo.Name; if (commandName != null) { // If we have a name, use it in the error message diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 5db5e5171df..76376f36a3b 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -4432,11 +4432,7 @@ private void CoreInvoke(PSDataCollection input, PSDataC finally { RunningExtraCommands = false; - - if (_isBatching) - { - EndAsyncBatchExecution(); - } + EndAsyncBatchExecution(); } } else diff --git a/src/System.Management.Automation/engine/interpreter/CallInstruction.cs b/src/System.Management.Automation/engine/interpreter/CallInstruction.cs index 88795b73cd8..bcaca8bda38 100644 --- a/src/System.Management.Automation/engine/interpreter/CallInstruction.cs +++ b/src/System.Management.Automation/engine/interpreter/CallInstruction.cs @@ -213,7 +213,7 @@ private static Type TryGetParameterOrReturnType(MethodInfo target, ParameterInfo private static bool IndexIsNotReturnType(int index, MethodInfo target, ParameterInfo[] pi) { - return pi.Length != index || (pi.Length == index && !target.IsStatic); + return pi.Length != index || !target.IsStatic; } /// diff --git a/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs b/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs index 6fdc756e7ab..9bf1630c92b 100644 --- a/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs +++ b/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs @@ -429,7 +429,7 @@ public override int Run(InterpretedFrame frame) // In the second path, the continuation mechanism is not involved and frame.InstructionIndex is not updated #if DEBUG bool isFromJump = frame.IsJumpHappened(); - Debug.Assert(!isFromJump || (isFromJump && _tryHandler.FinallyStartIndex == frame.InstructionIndex), "we should already jump to the first instruction of the finally"); + Debug.Assert(!isFromJump || _tryHandler.FinallyStartIndex == frame.InstructionIndex, "we should already jump to the first instruction of the finally"); #endif // run the finally block // we cannot jump out of the finally block, and we cannot have an immediate rethrow in it diff --git a/src/System.Management.Automation/engine/interpreter/InterpretedFrame.cs b/src/System.Management.Automation/engine/interpreter/InterpretedFrame.cs index 1cd7894b911..7f89a41edcd 100644 --- a/src/System.Management.Automation/engine/interpreter/InterpretedFrame.cs +++ b/src/System.Management.Automation/engine/interpreter/InterpretedFrame.cs @@ -313,7 +313,7 @@ public int Goto(int labelIndex, object value, bool gotoExceptionHandler) { // TODO: we know this at compile time (except for compiled loop): RuntimeLabel target = Interpreter._labels[labelIndex]; - Debug.Assert(!gotoExceptionHandler || (gotoExceptionHandler && _continuationIndex == target.ContinuationStackDepth), + Debug.Assert(!gotoExceptionHandler || _continuationIndex == target.ContinuationStackDepth, "When it's time to jump to the exception handler, all previous finally blocks should already be processed"); if (_continuationIndex == target.ContinuationStackDepth) diff --git a/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs b/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs index a1ba8526465..13d46759f06 100644 --- a/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs +++ b/src/System.Management.Automation/engine/remoting/client/ClientMethodExecutor.cs @@ -118,9 +118,7 @@ internal static void Dispatch( // Cmdlet case: queue up the executor in the pipeline stream. if (isMethodExecutorStreamEnabled) { - Dbg.Assert(!isMethodExecutorStreamEnabled || - (isMethodExecutorStreamEnabled && methodExecutorStream != null), - "method executor stream can't be null when enabled"); + Dbg.Assert(methodExecutorStream != null, "method executor stream can't be null when enabled"); methodExecutorStream.Write(methodExecutor); } diff --git a/src/System.Management.Automation/engine/remoting/client/PSProxyJob.cs b/src/System.Management.Automation/engine/remoting/client/PSProxyJob.cs index 3f9bbe36327..59f40b58c9c 100644 --- a/src/System.Management.Automation/engine/remoting/client/PSProxyJob.cs +++ b/src/System.Management.Automation/engine/remoting/client/PSProxyJob.cs @@ -769,8 +769,7 @@ private static ICollection Create(Runspace runspace, RunspacePool ru using (PowerShell ps = PowerShell.Create()) { - Dbg.Assert(runspacePool == null && runspace != null || - runspace == null && runspacePool != null, "Either a runspace or a runspacepool should be used, not both."); + Dbg.Assert(runspacePool == null ^ runspace == null, "Either a runspace or a runspacepool should be used, not both."); if (runspacePool == null) { @@ -1493,9 +1492,7 @@ private void CleanupReceivePowerShell(IAsyncResult asyncResult) /// happen private void AssignRunspaceOrRunspacePool(PowerShell powershell) { - Dbg.Assert(_runspacePool == null && _runspace != null || - _runspace == null && _runspacePool != null, - "Either a runspace or a runspacepool should be assigned to the proxy job"); + Dbg.Assert(_runspacePool == null ^ _runspace == null, "Either a runspace or a runspacepool should be assigned to the proxy job"); if (_runspacePool == null) { diff --git a/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs b/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs index 73629a3f62a..37b7f41647b 100644 --- a/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs +++ b/src/System.Management.Automation/engine/remoting/client/remotepipeline.cs @@ -912,8 +912,7 @@ private void InitPowerShellForConnect(bool syncCall) // Check to see if this pipeline already exists in the runspace. RemotePipeline currentPipeline = (RemotePipeline)((RemoteRunspace)_runspace).GetCurrentlyRunningPipeline(); - if (currentPipeline == null || - currentPipeline != null && !ReferenceEquals(currentPipeline, this)) + if (!ReferenceEquals(currentPipeline, this)) { ((RemoteRunspace)_runspace).DoConcurrentCheckAndAddToRunningPipelines(this, syncCall); } diff --git a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs index 813e3161716..842b0206f07 100644 --- a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs @@ -1173,10 +1173,7 @@ protected override void EndProcessing() WriteJobResults(false); // finally dispose the job. - if (!_asjob) - { - _job.Dispose(); - } + _job.Dispose(); // We no longer need to call ClearInvokeCommandOnRunspaces() here because // this command might finish before the foreach block finishes. previously, @@ -1223,10 +1220,8 @@ protected override void EndProcessing() WriteJobResults(false); // finally dispose the job. - if (!_asjob) - { - _job.Dispose(); - } + _job.Dispose(); + } // if (needToCollect... }// else - job == null } diff --git a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs index 2616ed72cf3..4860f782d13 100644 --- a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs +++ b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs @@ -1212,11 +1212,6 @@ internal void ConstructUri(String scheme, String computerName, Nullable p PortSetting = -1; UseDefaultWSManPort = true; } - else if (port.Value == DefaultPortHttp || port.Value == DefaultPortHttps) - { - PortSetting = port.Value; - UseDefaultWSManPort = false; - } else { PortSetting = port.Value; diff --git a/src/System.Management.Automation/security/Authenticode.cs b/src/System.Management.Automation/security/Authenticode.cs index d79aad4b0f9..d5d671b275d 100644 --- a/src/System.Management.Automation/security/Authenticode.cs +++ b/src/System.Management.Automation/security/Authenticode.cs @@ -619,7 +619,7 @@ private static Signature GetSignatureFromWintrustData( } } - Diagnostics.Assert(((error == 0) && (signature != null)) || (error != 0), "GetSignatureFromWintrustData: general crypto failure"); + Diagnostics.Assert(error != 0 || signature != null, "GetSignatureFromWintrustData: general crypto failure"); if ((signature == null) && (error != 0)) {