diff --git a/.globalconfig b/.globalconfig index ced5ff22453..90c895c2bc9 100644 --- a/.globalconfig +++ b/.globalconfig @@ -1184,7 +1184,7 @@ dotnet_diagnostic.SA1129.severity = none dotnet_diagnostic.SA1130.severity = none # SA1131: Use readable conditions -dotnet_diagnostic.SA1131.severity = none +dotnet_diagnostic.SA1131.severity = warning # SA1132: Do not combine fields dotnet_diagnostic.SA1132.severity = none diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs index 24b142a5081..291bb967c42 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs @@ -325,37 +325,37 @@ private enum JobOutputs private static void DiscardJobOutputs(Job job, JobOutputs jobOutputsToDiscard) { - if (JobOutputs.Output == (jobOutputsToDiscard & JobOutputs.Output)) + if ((jobOutputsToDiscard & JobOutputs.Output) == JobOutputs.Output) { DiscardJobOutputs(job.Output); } - if (JobOutputs.Error == (jobOutputsToDiscard & JobOutputs.Error)) + if ((jobOutputsToDiscard & JobOutputs.Error) == JobOutputs.Error) { DiscardJobOutputs(job.Error); } - if (JobOutputs.Warning == (jobOutputsToDiscard & JobOutputs.Warning)) + if ((jobOutputsToDiscard & JobOutputs.Warning) == JobOutputs.Warning) { DiscardJobOutputs(job.Warning); } - if (JobOutputs.Verbose == (jobOutputsToDiscard & JobOutputs.Verbose)) + if ((jobOutputsToDiscard & JobOutputs.Verbose) == JobOutputs.Verbose) { DiscardJobOutputs(job.Verbose); } - if (JobOutputs.Debug == (jobOutputsToDiscard & JobOutputs.Debug)) + if ((jobOutputsToDiscard & JobOutputs.Debug) == JobOutputs.Debug) { DiscardJobOutputs(job.Debug); } - if (JobOutputs.Progress == (jobOutputsToDiscard & JobOutputs.Progress)) + if ((jobOutputsToDiscard & JobOutputs.Progress) == JobOutputs.Progress) { DiscardJobOutputs(job.Progress); } - if (JobOutputs.Results == (jobOutputsToDiscard & JobOutputs.Results)) + if ((jobOutputsToDiscard & JobOutputs.Results) == JobOutputs.Results) { DiscardJobOutputs(job.Results); } diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/ExtrinsicMethodInvocationJob.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/ExtrinsicMethodInvocationJob.cs index 990c31c73a5..ea2c3d0f4b2 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/ExtrinsicMethodInvocationJob.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/ExtrinsicMethodInvocationJob.cs @@ -61,7 +61,7 @@ private void ProcessOutParameter(CimMethodResult methodResult, MethodParameter m object valueReturnedFromMethod = (outParameter == null) ? null : outParameter.Value; object dotNetValue = CimValueConverter.ConvertFromCimToDotNet(valueReturnedFromMethod, methodParameter.ParameterType); - if (MethodParameterBindings.Out == (methodParameter.Bindings & MethodParameterBindings.Out)) + if ((methodParameter.Bindings & MethodParameterBindings.Out) == MethodParameterBindings.Out) { methodParameter.Value = dotNetValue; cmdletOutput.Add(methodParameter.Name, methodParameter); @@ -81,7 +81,7 @@ private void ProcessOutParameter(CimMethodResult methodResult, MethodParameter m CimCmdletAdapter.AssociateSessionOfOriginWithInstance(cimInstance, this.JobContext.Session); } } - else if (MethodParameterBindings.Error == (methodParameter.Bindings & MethodParameterBindings.Error)) + else if ((methodParameter.Bindings & MethodParameterBindings.Error) == MethodParameterBindings.Error) { var gotError = (bool)LanguagePrimitives.ConvertTo(dotNetValue, typeof(bool), CultureInfo.InvariantCulture); if (gotError) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs index 0f442b5e5e2..a5f80af87d7 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs @@ -666,7 +666,7 @@ private PSObject AddProperties(ServiceController service) lpDatabaseName: null, dwDesiredAccess: NativeMethods.SC_MANAGER_CONNECT ); - if (IntPtr.Zero == hScManager) + if (hScManager == IntPtr.Zero) { lastError = Marshal.GetLastWin32Error(); Win32Exception exception = new Win32Exception(lastError); @@ -683,7 +683,7 @@ private PSObject AddProperties(ServiceController service) service.ServiceName, NativeMethods.SERVICE_QUERY_CONFIG ); - if (IntPtr.Zero == hService) + if (hService == IntPtr.Zero) { lastError = Marshal.GetLastWin32Error(); Win32Exception exception = new Win32Exception(lastError); @@ -737,7 +737,7 @@ private PSObject AddProperties(ServiceController service) } finally { - if (IntPtr.Zero != hService) + if (hService != IntPtr.Zero) { bool succeeded = NativeMethods.CloseServiceHandle(hService); if (!succeeded) @@ -746,7 +746,7 @@ private PSObject AddProperties(ServiceController service) } } - if (IntPtr.Zero != hScManager) + if (hScManager != IntPtr.Zero) { bool succeeded = NativeMethods.CloseServiceHandle(hScManager); if (!succeeded) @@ -907,14 +907,14 @@ internal bool DoStartService(ServiceController serviceController) } catch (Win32Exception e) { - if (NativeMethods.ERROR_SERVICE_ALREADY_RUNNING != e.NativeErrorCode) + if (e.NativeErrorCode != NativeMethods.ERROR_SERVICE_ALREADY_RUNNING) exception = e; } catch (InvalidOperationException e) { Win32Exception eInner = e.InnerException as Win32Exception; if (eInner == null - || NativeMethods.ERROR_SERVICE_ALREADY_RUNNING != eInner.NativeErrorCode) + || eInner.NativeErrorCode != NativeMethods.ERROR_SERVICE_ALREADY_RUNNING) { exception = e; } @@ -1024,7 +1024,7 @@ internal List DoStopService(ServiceController serviceControll } catch (Win32Exception e) { - if (NativeMethods.ERROR_SERVICE_NOT_ACTIVE != e.NativeErrorCode) + if (e.NativeErrorCode != NativeMethods.ERROR_SERVICE_NOT_ACTIVE) exception = e; } catch (InvalidOperationException e) @@ -1032,7 +1032,7 @@ internal List DoStopService(ServiceController serviceControll Win32Exception eInner = e.InnerException as Win32Exception; if (eInner == null - || NativeMethods.ERROR_SERVICE_NOT_ACTIVE != eInner.NativeErrorCode) + || eInner.NativeErrorCode != NativeMethods.ERROR_SERVICE_NOT_ACTIVE) { exception = e; } @@ -1117,7 +1117,7 @@ internal bool DoPauseService(ServiceController serviceController) } catch (Win32Exception e) { - if (NativeMethods.ERROR_SERVICE_NOT_ACTIVE == e.NativeErrorCode) + if (e.NativeErrorCode == NativeMethods.ERROR_SERVICE_NOT_ACTIVE) { serviceNotRunning = true; } @@ -1128,7 +1128,7 @@ internal bool DoPauseService(ServiceController serviceController) { Win32Exception eInner = e.InnerException as Win32Exception; if (eInner != null - && NativeMethods.ERROR_SERVICE_NOT_ACTIVE == eInner.NativeErrorCode) + && eInner.NativeErrorCode == NativeMethods.ERROR_SERVICE_NOT_ACTIVE) { serviceNotRunning = true; } @@ -1198,7 +1198,7 @@ internal bool DoResumeService(ServiceController serviceController) } catch (Win32Exception e) { - if (NativeMethods.ERROR_SERVICE_NOT_ACTIVE == e.NativeErrorCode) + if (e.NativeErrorCode == NativeMethods.ERROR_SERVICE_NOT_ACTIVE) { serviceNotRunning = true; } @@ -1209,7 +1209,7 @@ internal bool DoResumeService(ServiceController serviceController) { Win32Exception eInner = e.InnerException as Win32Exception; if (eInner != null - && NativeMethods.ERROR_SERVICE_NOT_ACTIVE == eInner.NativeErrorCode) + && eInner.NativeErrorCode == NativeMethods.ERROR_SERVICE_NOT_ACTIVE) { serviceNotRunning = true; } @@ -1737,7 +1737,7 @@ protected override void ProcessRecord() NativeMethods.SC_MANAGER_CONNECT ); - if (IntPtr.Zero == hScManager) + if (hScManager == IntPtr.Zero) { int lastError = Marshal.GetLastWin32Error(); Win32Exception exception = new Win32Exception(lastError); @@ -1756,7 +1756,7 @@ protected override void ProcessRecord() NativeMethods.SERVICE_CHANGE_CONFIG | NativeMethods.WRITE_DAC | NativeMethods.WRITE_OWNER ); - if (IntPtr.Zero == hService) + if (hService == IntPtr.Zero) { int lastError = Marshal.GetLastWin32Error(); Win32Exception exception = new Win32Exception(lastError); @@ -1770,7 +1770,7 @@ protected override void ProcessRecord() } // Modify startup type or display name or credential if (!string.IsNullOrEmpty(DisplayName) - || ServiceStartupType.InvalidValue != StartupType || Credential != null) + || StartupType != ServiceStartupType.InvalidValue || Credential != null) { DWORD dwStartType = NativeMethods.SERVICE_NO_CHANGE; if (!NativeMethods.TryGetNativeStartupType(StartupType, out dwStartType)) @@ -1920,12 +1920,12 @@ protected override void ProcessRecord() } finally { - if (IntPtr.Zero != delayedAutoStartInfoBuffer) + if (delayedAutoStartInfoBuffer != IntPtr.Zero) { Marshal.FreeCoTaskMem(delayedAutoStartInfoBuffer); } - if (IntPtr.Zero != hService) + if (hService != IntPtr.Zero) { bool succeeded = NativeMethods.CloseServiceHandle(hService); if (!succeeded) @@ -1941,7 +1941,7 @@ protected override void ProcessRecord() } } - if (IntPtr.Zero != hScManager) + if (hScManager != IntPtr.Zero) { bool succeeded = NativeMethods.CloseServiceHandle(hScManager); if (!succeeded) @@ -1960,7 +1960,7 @@ protected override void ProcessRecord() } finally { - if (IntPtr.Zero != password) + if (password != IntPtr.Zero) { Marshal.ZeroFreeCoTaskMemUnicode(password); } @@ -2133,7 +2133,7 @@ protected override void BeginProcessing() null, NativeMethods.SC_MANAGER_CONNECT | NativeMethods.SC_MANAGER_CREATE_SERVICE ); - if (IntPtr.Zero == hScManager) + if (hScManager == IntPtr.Zero) { int lastError = Marshal.GetLastWin32Error(); Win32Exception exception = new Win32Exception(lastError); @@ -2210,7 +2210,7 @@ protected override void BeginProcessing() username, password ); - if (IntPtr.Zero == hService) + if (hService == IntPtr.Zero) { int lastError = Marshal.GetLastWin32Error(); Win32Exception exception = new Win32Exception(lastError); @@ -2292,17 +2292,17 @@ protected override void BeginProcessing() } finally { - if (IntPtr.Zero != delayedAutoStartInfoBuffer) + if (delayedAutoStartInfoBuffer != IntPtr.Zero) { Marshal.FreeCoTaskMem(delayedAutoStartInfoBuffer); } - if (IntPtr.Zero != password) + if (password != IntPtr.Zero) { Marshal.ZeroFreeCoTaskMemUnicode(password); } - if (IntPtr.Zero != hService) + if (hService != IntPtr.Zero) { bool succeeded = NativeMethods.CloseServiceHandle(hService); if (!succeeded) @@ -2320,7 +2320,7 @@ protected override void BeginProcessing() } } - if (IntPtr.Zero != hScManager) + if (hScManager != IntPtr.Zero) { bool succeeded = NativeMethods.CloseServiceHandle(hScManager); if (!succeeded) @@ -2432,7 +2432,7 @@ protected override void ProcessRecord() lpDatabaseName: null, dwDesiredAccess: NativeMethods.SC_MANAGER_ALL_ACCESS ); - if (IntPtr.Zero == hScManager) + if (hScManager == IntPtr.Zero) { int lastError = Marshal.GetLastWin32Error(); Win32Exception exception = new Win32Exception(lastError); @@ -2451,7 +2451,7 @@ protected override void ProcessRecord() Name, NativeMethods.SERVICE_DELETE ); - if (IntPtr.Zero == hService) + if (hService == IntPtr.Zero) { int lastError = Marshal.GetLastWin32Error(); Win32Exception exception = new Win32Exception(lastError); @@ -2480,7 +2480,7 @@ protected override void ProcessRecord() } finally { - if (IntPtr.Zero != hService) + if (hService != IntPtr.Zero) { bool succeeded = NativeMethods.CloseServiceHandle(hService); if (!succeeded) @@ -2490,7 +2490,7 @@ protected override void ProcessRecord() } } - if (IntPtr.Zero != hScManager) + if (hScManager != IntPtr.Zero) { bool succeeded = NativeMethods.CloseServiceHandle(hScManager); if (!succeeded) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs index 62c6bc104ea..34d9b415619 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs @@ -82,7 +82,7 @@ protected override void ProcessRecord() foreach (string tzname in Name) { TimeZoneInfo[] timeZones = TimeZoneHelper.LookupSystemTimeZoneInfoByName(tzname); - if (0 < timeZones.Length) + if (timeZones.Length > 0) { // manually process each object in the array, so if there is only a single // entry then the returned type is TimeZoneInfo and not TimeZoneInfo[], and @@ -198,7 +198,7 @@ protected override void ProcessRecord() ErrorCategory.InvalidArgument, "Name")); } - else if (1 < timeZones.Length) + else if (timeZones.Length > 1) { string message = string.Format(CultureInfo.InvariantCulture, TimeZoneResources.MultipleMatchingTimeZones, Name); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs index 7181bbeadaf..48cc3b3ca86 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs @@ -208,7 +208,7 @@ private void Process(OrderByPropertyEntry differenceEntry) // Add differenceEntry to differenceEntryBacklog if (differenceEntry != null) { - if (0 < SyncWindow) + if (SyncWindow > 0) { while (_differenceEntryBacklog.Count >= SyncWindow) { @@ -234,7 +234,7 @@ private void Process(OrderByPropertyEntry differenceEntry) // Add referenceEntry to referenceEntryBacklog if (referenceEntry != null) { - if (0 < SyncWindow) + if (SyncWindow > 0) { while (_referenceEntryBacklog.Count >= SyncWindow) { @@ -406,7 +406,7 @@ protected override void ProcessRecord() return; } - if (_comparer == null && 0 < DifferenceObject.Length) + if (_comparer == null && DifferenceObject.Length > 0) { InitComparer(); } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index d13cecdf543..744c40135ce 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -655,7 +655,7 @@ internal virtual void PrepareSession() WebSession.Proxy = webProxy; } - if (-1 < MaximumRedirection) + if (MaximumRedirection > -1) { WebSession.MaximumRedirection = MaximumRedirection; } @@ -777,7 +777,7 @@ private string FormatDictionary(IDictionary content) StringBuilder bodyBuilder = new StringBuilder(); foreach (string key in content.Keys) { - if (0 < bodyBuilder.Length) + if (bodyBuilder.Length > 0) { bodyBuilder.Append('&'); } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs index 70c5721dbc1..e365c77ede3 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs @@ -200,7 +200,7 @@ private void SetResponse(HttpResponseMessage response, Stream contentStream) } long contentLength = response.Content.Headers.ContentLength.Value; - if (0 >= contentLength) + if (contentLength <= 0) { contentLength = StreamHelper.DefaultReadBuffer; } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs index 7d2eaefcfc1..a1073234867 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs @@ -220,7 +220,7 @@ private void Initialize() long totalLength = 0; byte[] buffer = new byte[StreamHelper.ChunkSize]; ProgressRecord record = new ProgressRecord(StreamHelper.ActivityId, WebCmdletStrings.ReadResponseProgressActivity, "statusDescriptionPlaceholder"); - for (int read = 1; 0 < read; totalLength += read) + for (int read = 1; read > 0; totalLength += read) { if (_ownerCmdlet != null) { @@ -235,7 +235,7 @@ private void Initialize() read = _originalStreamToProxy.Read(buffer, 0, buffer.Length); - if (0 < read) + if (read > 0) { base.Write(buffer, 0, read); } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index bbe0a82bb15..e49002ac1d8 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -315,7 +315,7 @@ private object ReadLineSafe(bool isSecureString, char? printToken) // Handle Ctrl-C ending input if (keyInfo.Key == ConsoleKey.C && keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control)) #else - if (string.IsNullOrEmpty(key) || (char)3 == key[0]) + if (string.IsNullOrEmpty(key) || key[0] == (char)3) #endif { PipelineStoppedException e = new PipelineStoppedException(); @@ -324,7 +324,7 @@ private object ReadLineSafe(bool isSecureString, char? printToken) #if UNIX if (keyInfo.Key == ConsoleKey.Enter) #else - if ((char)13 == key[0]) + if (key[0] == (char)13) #endif { // @@ -335,7 +335,7 @@ private object ReadLineSafe(bool isSecureString, char? printToken) #if UNIX if (keyInfo.Key == ConsoleKey.Backspace) #else - if ((char)8 == key[0]) + if (key[0] == (char)8) #endif { // diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index e60b817d4ec..02cc0aaf4d1 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -272,7 +272,7 @@ protected override bool ReleaseHandle() { bool fResult = false; - if (IntPtr.Zero != handle) + if (handle != IntPtr.Zero) { fResult = Security.NativeMethods.CertCloseStore(handle, 0); handle = IntPtr.Zero; @@ -349,7 +349,7 @@ public void Open(bool includeArchivedCerts) IntPtr.Zero, // hCryptProv StoreFlags, _storeName); - if (IntPtr.Zero == hCertStore) + if (hCertStore == IntPtr.Zero) { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); } @@ -441,7 +441,7 @@ public IntPtr GetCertByName(string Name) while (true) { certContext = GetNextCert(certContext); - if (IntPtr.Zero == certContext) + if (certContext == IntPtr.Zero) { break; } @@ -986,7 +986,7 @@ protected override void NewItem( IntPtr.Zero, // hCryptProv StoreFlags, pathElements[1]); - if (IntPtr.Zero == hCertStore) + if (hCertStore == IntPtr.Zero) { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); } @@ -1083,7 +1083,7 @@ protected override bool HasChildItems(string path) { store.Open(IncludeArchivedCerts()); IntPtr certContext = store.GetFirstCert(); - if (IntPtr.Zero != certContext) + if (certContext != IntPtr.Zero) { store.FreeCert(certContext); result = true; @@ -1749,7 +1749,7 @@ private void RemoveCertStore(string storeName, bool fDeleteKey, string sourcePat // if recurse is true, remove every cert in the store IntPtr localName = Security.NativeMethods.CryptFindLocalizedName(storeName); string[] pathElements = GetPathElements(sourcePath); - if (IntPtr.Zero == localName)//not find, we can remove + if (localName == IntPtr.Zero)//not find, we can remove { X509NativeStore store = null; @@ -1763,7 +1763,7 @@ private void RemoveCertStore(string storeName, bool fDeleteKey, string sourcePat // enumerate over each cert and remove it // IntPtr certContext = store.GetFirstCert(); - while (IntPtr.Zero != certContext) + while (certContext != IntPtr.Zero) { X509Certificate2 cert = new X509Certificate2(certContext); string certPath = sourcePath + cert.Thumbprint; @@ -2098,7 +2098,7 @@ private object GetItemAtPath(string path, bool test, out bool isContainer) store.Open(IncludeArchivedCerts()); IntPtr certContext = store.GetCertByName(pathElements[2]); - if (IntPtr.Zero == certContext) + if (certContext == IntPtr.Zero) { if (test) { @@ -2449,7 +2449,7 @@ private void GetCertificatesOrNames(string path, // IntPtr certContext = store.GetFirstCert(); - while (IntPtr.Zero != certContext) + while (certContext != IntPtr.Zero) { X509Certificate2 cert = new X509Certificate2(certContext); diff --git a/src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs b/src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs index 81a4c33062f..b92c2cbb78c 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/MethodInvocationInfo.cs @@ -57,7 +57,7 @@ internal IEnumerable GetArgumentsOfType() where T : class List result = new List(); foreach (var methodParameter in this.Parameters) { - if (MethodParameterBindings.In != (methodParameter.Bindings & MethodParameterBindings.In)) + if ((methodParameter.Bindings & MethodParameterBindings.In) != MethodParameterBindings.In) { continue; } diff --git a/src/System.Management.Automation/cimSupport/cmdletization/ScriptWriter.cs b/src/System.Management.Automation/cimSupport/cmdletization/ScriptWriter.cs index 3757319c9ab..1d5bf0e26da 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/ScriptWriter.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/ScriptWriter.cs @@ -1086,7 +1086,7 @@ private static void GenerateSingleMethodParameterProcessing( prefix); } - if (MethodParameterBindings.In == (methodParameterBindings & MethodParameterBindings.In)) + if ((methodParameterBindings & MethodParameterBindings.In) == MethodParameterBindings.In) { Dbg.Assert(cmdletParameterName != null, "Called should verify cmdletParameterName!=null for 'in' parameters"); @@ -1114,7 +1114,7 @@ private static void GenerateSingleMethodParameterProcessing( CodeGeneration.EscapeSingleQuotedStringContent(cmdletParameterTypeName), CodeGeneration.EscapeSingleQuotedStringContent(methodParameterBindings.ToString())); - if (MethodParameterBindings.In == (methodParameterBindings & MethodParameterBindings.In)) + if ((methodParameterBindings & MethodParameterBindings.In) == MethodParameterBindings.In) { output.WriteLine("{0}}}", prefix); } @@ -1222,7 +1222,7 @@ string parameterSetName in methodParameter.ParameterName, methodParameterBindings); - if (MethodParameterBindings.Out == (methodParameterBindings & MethodParameterBindings.Out)) + if ((methodParameterBindings & MethodParameterBindings.Out) == MethodParameterBindings.Out) { typesOfOutParameters.Add(dotNetTypeOfParameter); etsTypesOfOutParameters.Add(methodParameter.Type.ETSType); @@ -1246,7 +1246,7 @@ string parameterSetName in CodeGeneration.EscapeSingleQuotedStringContent(method.ReturnValue.Type.ETSType)); } - if (MethodParameterBindings.Out == (methodParameterBindings & MethodParameterBindings.Out)) + if ((methodParameterBindings & MethodParameterBindings.Out) == MethodParameterBindings.Out) { typesOfOutParameters.Add(dotNetTypeOfParameter); etsTypesOfOutParameters.Add(method.ReturnValue.Type.ETSType); @@ -1363,7 +1363,7 @@ private void GenerateMethodParametersProcessing( methodParameter.ParameterName, methodParameterBindings); - if (MethodParameterBindings.Out == (methodParameterBindings & MethodParameterBindings.Out)) + if ((methodParameterBindings & MethodParameterBindings.Out) == MethodParameterBindings.Out) { typesOfOutParameters.Add(dotNetTypeOfParameter); etsTypesOfOutParameters.Add(methodParameter.Type.ETSType); @@ -1387,7 +1387,7 @@ private void GenerateMethodParametersProcessing( CodeGeneration.EscapeSingleQuotedStringContent(method.ReturnValue.Type.ETSType)); } - if (MethodParameterBindings.Out == (methodParameterBindings & MethodParameterBindings.Out)) + if ((methodParameterBindings & MethodParameterBindings.Out) == MethodParameterBindings.Out) { typesOfOutParameters.Add(dotNetTypeOfParameter); etsTypesOfOutParameters.Add(method.ReturnValue.Type.ETSType); @@ -1861,7 +1861,7 @@ private string GetHelpDirectiveForExternalHelp() { StringBuilder output = new StringBuilder(); - if (GenerationOptions.HelpXml == (_generationOptions & GenerationOptions.HelpXml)) + if ((_generationOptions & GenerationOptions.HelpXml) == GenerationOptions.HelpXml) { output.AppendFormat( CultureInfo.InvariantCulture, diff --git a/src/System.Management.Automation/cimSupport/cmdletization/cim/WildcardPatternToCimQueryParser.cs b/src/System.Management.Automation/cimSupport/cmdletization/cim/WildcardPatternToCimQueryParser.cs index 4ce8a854487..d4b401ade60 100644 --- a/src/System.Management.Automation/cimSupport/cmdletization/cim/WildcardPatternToCimQueryParser.cs +++ b/src/System.Management.Automation/cimSupport/cmdletization/cim/WildcardPatternToCimQueryParser.cs @@ -79,13 +79,13 @@ protected override void AppendCharacterRangeToBracketExpression(char startOfChar // 93 = ] // 94 = ^ // 95 = _ - if ((91 <= startOfCharacterRange) && (startOfCharacterRange <= 94)) + if ((startOfCharacterRange >= 91) && (startOfCharacterRange <= 94)) { startOfCharacterRange = (char)90; _needClientSideFiltering = true; } - if ((91 <= endOfCharacterRange) && (endOfCharacterRange <= 94)) + if ((endOfCharacterRange >= 91) && (endOfCharacterRange <= 94)) { endOfCharacterRange = (char)95; _needClientSideFiltering = true; diff --git a/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs b/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs index 81ccb73133b..7adda9937c9 100644 --- a/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs +++ b/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs @@ -366,7 +366,7 @@ public override bool IsSettable(PSAdaptedProperty adaptedProperty) return false; } - bool isReadOnly = (CimFlags.ReadOnly == (cimProperty.Flags & CimFlags.ReadOnly)); + bool isReadOnly = ((cimProperty.Flags & CimFlags.ReadOnly) == CimFlags.ReadOnly); bool isSettable = !isReadOnly; return isSettable; } diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index e7c8ea0be9a..b31a161c350 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -5367,7 +5367,7 @@ private static string GetCimPropertyToString(CimPropertyDeclaration cimProperty) break; } - bool isReadOnly = (CimFlags.ReadOnly == (cimProperty.Flags & CimFlags.ReadOnly)); + bool isReadOnly = ((cimProperty.Flags & CimFlags.ReadOnly) == CimFlags.ReadOnly); return type + " " + cimProperty.Name + " { get; " + (isReadOnly ? "}" : "set; }"); } diff --git a/src/System.Management.Automation/engine/CommandMetadata.cs b/src/System.Management.Automation/engine/CommandMetadata.cs index aa3db8a3740..027373ec676 100644 --- a/src/System.Management.Automation/engine/CommandMetadata.cs +++ b/src/System.Management.Automation/engine/CommandMetadata.cs @@ -1316,7 +1316,7 @@ public static Dictionary GetRestrictedCommands(SessionC List restrictedCommands = new List(); // all remoting cmdlets need to be included for workflow scenarios as wel - if (SessionCapabilities.RemoteServer == (sessionCapabilities & SessionCapabilities.RemoteServer)) + if ((sessionCapabilities & SessionCapabilities.RemoteServer) == SessionCapabilities.RemoteServer) { restrictedCommands.AddRange(GetRestrictedRemotingCommands()); } diff --git a/src/System.Management.Automation/engine/CoreAdapter.cs b/src/System.Management.Automation/engine/CoreAdapter.cs index 673225b996b..89114771ede 100644 --- a/src/System.Management.Automation/engine/CoreAdapter.cs +++ b/src/System.Management.Automation/engine/CoreAdapter.cs @@ -5939,7 +5939,7 @@ private static MethodInfo Infer(MethodInfo genericMethod, ICollection type using (s_tracer.TraceScope("Inferring type parameters for the following method: {0}", genericMethod)) { - if (PSTraceSourceOptions.WriteLine == (s_tracer.Options & PSTraceSourceOptions.WriteLine)) + if ((s_tracer.Options & PSTraceSourceOptions.WriteLine) == PSTraceSourceOptions.WriteLine) { s_tracer.WriteLine( "Types of method arguments: {0}", diff --git a/src/System.Management.Automation/engine/ErrorPackage.cs b/src/System.Management.Automation/engine/ErrorPackage.cs index 4d1627dff93..948e9c5c0f8 100644 --- a/src/System.Management.Automation/engine/ErrorPackage.cs +++ b/src/System.Management.Automation/engine/ErrorPackage.cs @@ -495,7 +495,7 @@ public override string ToString() /// internal static string Ellipsize(CultureInfo uiCultureInfo, string original) { - if (40 >= original.Length) + if (original.Length <= 40) { return original; } diff --git a/src/System.Management.Automation/engine/ExecutionContext.cs b/src/System.Management.Automation/engine/ExecutionContext.cs index 3a726be8f73..0b6e9d8b9e9 100644 --- a/src/System.Management.Automation/engine/ExecutionContext.cs +++ b/src/System.Management.Automation/engine/ExecutionContext.cs @@ -906,7 +906,7 @@ internal void AppendDollarError(object obj) const int maxErrorCount = 256; int numToErase = arraylist.Count - (maxErrorCount - 1); - if (0 < numToErase) + if (numToErase > 0) { arraylist.RemoveRange( maxErrorCount - 1, diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 8d9b01ad134..17ccb75163d 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -1346,7 +1346,7 @@ public static InitialSessionState CreateFromSessionConfigurationFile(string path public static InitialSessionState CreateRestricted(SessionCapabilities sessionCapabilities) { // only remote server has been requested - if (SessionCapabilities.RemoteServer == sessionCapabilities) + if (sessionCapabilities == SessionCapabilities.RemoteServer) { return CreateRestrictedForRemoteServer(); } diff --git a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs index 65c2931db0f..853f00bf177 100644 --- a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs +++ b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs @@ -815,7 +815,7 @@ private static IEnumerable GetCimModules( ErrorRecord errorRecord = GetErrorRecordForRemoteDiscoveryProvider(exception); if (!cmdlet.MyInvocation.ExpectingInput) { - if (((-1) != errorRecord.FullyQualifiedErrorId.IndexOf(DiscoveryProviderNotFoundErrorId, StringComparison.OrdinalIgnoreCase)) || + if ((errorRecord.FullyQualifiedErrorId.IndexOf(DiscoveryProviderNotFoundErrorId, StringComparison.OrdinalIgnoreCase) != (-1)) || (cancellationToken.IsCancellationRequested || (exception is OperationCanceledException)) || (!cimSession.TestConnection())) { diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index 2709ba1384e..43af0e45a9c 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -2844,20 +2844,20 @@ internal void _WriteErrorSkipAllowCheck(ErrorRecord errorRecord, ActionPreferenc } // No trace of the error in the 'Ignore' case - if (ActionPreference.Ignore == preference) + if (preference == ActionPreference.Ignore) { return; // do not write or record to output pipe } // 2004/05/26-JonN // The object is not written in the SilentlyContinue case - if (ActionPreference.SilentlyContinue == preference) + if (preference == ActionPreference.SilentlyContinue) { AppendErrorToVariables(errorRecord); return; // do not write to output pipe } - if (ContinueStatus.YesToAll == lastErrorContinueStatus) + if (lastErrorContinueStatus == ContinueStatus.YesToAll) { preference = ActionPreference.Continue; } @@ -3684,7 +3684,7 @@ bool hasSecurityImpact CBhost.EnterNestedPrompt(_thisCommand); // continue loop } - else if (-1 == response) + else if (response == -1) { ActionPreferenceStopException e = new ActionPreferenceStopException( diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index bcd42658d22..e5c12620e34 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -824,7 +824,7 @@ public int ParentId get { // Construct parent id only once. - if (int.MinValue == _parentId) + if (_parentId == int.MinValue) { ConstructParentId(); } diff --git a/src/System.Management.Automation/engine/PSConfiguration.cs b/src/System.Management.Automation/engine/PSConfiguration.cs index e6388f291c3..b36d1d941d5 100644 --- a/src/System.Management.Automation/engine/PSConfiguration.cs +++ b/src/System.Management.Automation/engine/PSConfiguration.cs @@ -566,7 +566,7 @@ private void UpdateValueInFile(ConfigScope scope, string key, T value, bool a /// The value to write. private void WriteValueToFile(ConfigScope scope, string key, T value) { - if (ConfigScope.CurrentUser == scope && !Directory.Exists(perUserConfigDirectory)) + if (scope == ConfigScope.CurrentUser && !Directory.Exists(perUserConfigDirectory)) { Directory.CreateDirectory(perUserConfigDirectory); } diff --git a/src/System.Management.Automation/engine/TypeMetadata.cs b/src/System.Management.Automation/engine/TypeMetadata.cs index 372497a0261..04ada04c56e 100644 --- a/src/System.Management.Automation/engine/TypeMetadata.cs +++ b/src/System.Management.Automation/engine/TypeMetadata.cs @@ -278,10 +278,10 @@ internal ParameterFlags Flags set { - this.IsMandatory = (ParameterFlags.Mandatory == (value & ParameterFlags.Mandatory)); - this.ValueFromPipeline = (ParameterFlags.ValueFromPipeline == (value & ParameterFlags.ValueFromPipeline)); - this.ValueFromPipelineByPropertyName = (ParameterFlags.ValueFromPipelineByPropertyName == (value & ParameterFlags.ValueFromPipelineByPropertyName)); - this.ValueFromRemainingArguments = (ParameterFlags.ValueFromRemainingArguments == (value & ParameterFlags.ValueFromRemainingArguments)); + this.IsMandatory = ((value & ParameterFlags.Mandatory) == ParameterFlags.Mandatory); + this.ValueFromPipeline = ((value & ParameterFlags.ValueFromPipeline) == ParameterFlags.ValueFromPipeline); + this.ValueFromPipelineByPropertyName = ((value & ParameterFlags.ValueFromPipelineByPropertyName) == ParameterFlags.ValueFromPipelineByPropertyName); + this.ValueFromRemainingArguments = ((value & ParameterFlags.ValueFromRemainingArguments) == ParameterFlags.ValueFromRemainingArguments); } } diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index 968e2c2aea6..84e1fb23936 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -49,7 +49,7 @@ internal static class Utils internal static bool TryCast(BigInteger value, out byte b) { - if (value < byte.MinValue || byte.MaxValue < value) + if (value < byte.MinValue || value > byte.MaxValue) { b = 0; return false; @@ -61,7 +61,7 @@ internal static bool TryCast(BigInteger value, out byte b) internal static bool TryCast(BigInteger value, out sbyte sb) { - if (value < sbyte.MinValue || sbyte.MaxValue < value) + if (value < sbyte.MinValue || value > sbyte.MaxValue) { sb = 0; return false; @@ -73,7 +73,7 @@ internal static bool TryCast(BigInteger value, out sbyte sb) internal static bool TryCast(BigInteger value, out short s) { - if (value < short.MinValue || short.MaxValue < value) + if (value < short.MinValue || value > short.MaxValue) { s = 0; return false; @@ -85,7 +85,7 @@ internal static bool TryCast(BigInteger value, out short s) internal static bool TryCast(BigInteger value, out ushort us) { - if (value < ushort.MinValue || ushort.MaxValue < value) + if (value < ushort.MinValue || value > ushort.MaxValue) { us = 0; return false; @@ -97,7 +97,7 @@ internal static bool TryCast(BigInteger value, out ushort us) internal static bool TryCast(BigInteger value, out int i) { - if (value < int.MinValue || int.MaxValue < value) + if (value < int.MinValue || value > int.MaxValue) { i = 0; return false; @@ -109,7 +109,7 @@ internal static bool TryCast(BigInteger value, out int i) internal static bool TryCast(BigInteger value, out uint u) { - if (value < uint.MinValue || uint.MaxValue < value) + if (value < uint.MinValue || value > uint.MaxValue) { u = 0; return false; @@ -121,7 +121,7 @@ internal static bool TryCast(BigInteger value, out uint u) internal static bool TryCast(BigInteger value, out long l) { - if (value < long.MinValue || long.MaxValue < value) + if (value < long.MinValue || value > long.MaxValue) { l = 0; return false; @@ -133,7 +133,7 @@ internal static bool TryCast(BigInteger value, out long l) internal static bool TryCast(BigInteger value, out ulong ul) { - if (value < ulong.MinValue || ulong.MaxValue < value) + if (value < ulong.MinValue || value > ulong.MaxValue) { ul = 0; return false; diff --git a/src/System.Management.Automation/engine/hostifaces/AsyncResult.cs b/src/System.Management.Automation/engine/hostifaces/AsyncResult.cs index fa965f4ab59..f1e57e6fe39 100644 --- a/src/System.Management.Automation/engine/hostifaces/AsyncResult.cs +++ b/src/System.Management.Automation/engine/hostifaces/AsyncResult.cs @@ -42,7 +42,7 @@ internal class AsyncResult : IAsyncResult /// internal AsyncResult(Guid ownerId, AsyncCallback callback, object state) { - Dbg.Assert(Guid.Empty != ownerId, "ownerId cannot be empty"); + Dbg.Assert(ownerId != Guid.Empty, "ownerId cannot be empty"); OwnerId = ownerId; Callback = callback; AsyncState = state; diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 11fc4592fb0..c5248e106b7 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -4602,7 +4602,7 @@ private void CoreInvokeRemoteHelper(PSDataCollection in psAsyncResult.EndInvoke(); EndInvokeAsyncResult = null; - if ((PSInvocationState.Failed == InvocationStateInfo.State) && + if ((InvocationStateInfo.State == PSInvocationState.Failed) && (InvocationStateInfo.Reason != null)) { throw InvocationStateInfo.Reason; diff --git a/src/System.Management.Automation/engine/parser/tokenizer.cs b/src/System.Management.Automation/engine/parser/tokenizer.cs index 3d66362745c..3379e62eb20 100644 --- a/src/System.Management.Automation/engine/parser/tokenizer.cs +++ b/src/System.Management.Automation/engine/parser/tokenizer.cs @@ -826,7 +826,7 @@ internal void FinishNestedScan(TokenizerState ts) private char GetChar() { - Diagnostics.Assert(0 <= _currentIndex, "GetChar reading before start of input."); + Diagnostics.Assert(_currentIndex >= 0, "GetChar reading before start of input."); Diagnostics.Assert(_currentIndex <= _script.Length + 1, "GetChar reading after end of input."); // Increment _currentIndex, even if it goes over the Length so callers can call UngetChar to unget EOF. @@ -848,7 +848,7 @@ private void UngetChar() private char PeekChar() { - Diagnostics.Assert(0 <= _currentIndex && _currentIndex <= _script.Length, "PeekChar out of range."); + Diagnostics.Assert(_currentIndex >= 0 && _currentIndex <= _script.Length, "PeekChar out of range."); if (_currentIndex == _script.Length) { @@ -1045,7 +1045,7 @@ internal void Resync(int start) { _currentIndex = _script.Length + 1; } - else if (0 > _currentIndex) + else if (_currentIndex < 0) { _currentIndex = 0; } diff --git a/src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs b/src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs index b1d9c968b10..4dba47814e2 100644 --- a/src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs +++ b/src/System.Management.Automation/engine/remoting/client/ThrottlingJob.cs @@ -387,7 +387,7 @@ internal void AddChildJobWithoutBlocking(StartableJob childJob, ChildJobFlags fl newJobStateInfo = new JobStateInfo(JobState.Running); } - if (ChildJobFlags.CreatesChildJobs == (ChildJobFlags.CreatesChildJobs & flags)) + if ((ChildJobFlags.CreatesChildJobs & flags) == ChildJobFlags.CreatesChildJobs) { _setOfChildJobsThatCanAddMoreChildJobs.Add(childJob.InstanceId); } diff --git a/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs b/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs index a6342196fa8..9ce1cb4b08f 100644 --- a/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs +++ b/src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs @@ -530,7 +530,7 @@ private void HandleRunspaceStateChanged(object sender, OperationStateEventArgs s transErrorCode, _defaultFQEID); - if (WSManNativeApi.ERROR_WSMAN_NO_LOGON_SESSION_EXIST == transErrorCode) + if (transErrorCode == WSManNativeApi.ERROR_WSMAN_NO_LOGON_SESSION_EXIST) { errorDetails += System.Environment.NewLine + string.Format(System.Globalization.CultureInfo.CurrentCulture, RemotingErrorIdStrings.RemotingErrorNoLogonSessionExist); } diff --git a/src/System.Management.Automation/engine/remoting/fanin/BaseTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/BaseTransportManager.cs index aa496990dd8..9a4f19e59f2 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/BaseTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/BaseTransportManager.cs @@ -1524,7 +1524,7 @@ internal static byte[] ExtractEncodedXmlElement(string xmlBuffer, string xmlTag) XmlReader reader = XmlReader.Create(new StringReader(xmlBuffer), readerSettings); string additionalData; - if (XmlNodeType.Element == reader.MoveToContent()) + if (reader.MoveToContent() == XmlNodeType.Element) { additionalData = reader.ReadElementContentAsString(xmlTag, reader.NamespaceURI); } diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs index 404dd3b576d..83e554f8199 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs @@ -192,7 +192,7 @@ internal static MarshalledObject Create(T obj) /// public void Dispose() { - if (IntPtr.Zero != _dataPtr) + if (_dataPtr != IntPtr.Zero) { Marshal.FreeHGlobal(_dataPtr); _dataPtr = IntPtr.Zero; @@ -869,7 +869,7 @@ internal static WSManData_UnToMan UnMarshal(IntPtr unmanagedData) { WSManData_UnToMan result = null; - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManDataStruct resultInternal = Marshal.PtrToStructure(unmanagedData); result = WSManData_UnToMan.UnMarshal(resultInternal); @@ -972,7 +972,7 @@ internal WSManStreamIDSet_ManToUn(string[] streamIds) /// internal void Dispose() { - if (IntPtr.Zero != _streamSetInfo.streamIDs) + if (_streamSetInfo.streamIDs != IntPtr.Zero) { int sizeOfIntPtr = Marshal.SizeOf(); for (int index = 0; index < _streamSetInfo.streamIDsCount; index++) @@ -980,7 +980,7 @@ internal void Dispose() IntPtr streamAddress = IntPtr.Zero; streamAddress = Marshal.ReadIntPtr(_streamSetInfo.streamIDs, index * sizeOfIntPtr); - if (IntPtr.Zero != streamAddress) + if (streamAddress != IntPtr.Zero) { Marshal.FreeHGlobal(streamAddress); streamAddress = IntPtr.Zero; @@ -1019,7 +1019,7 @@ internal static WSManStreamIDSet_UnToMan UnMarshal(IntPtr unmanagedData) { WSManStreamIDSet_UnToMan result = null; - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManStreamIDSetStruct resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -1140,7 +1140,7 @@ internal WSManOptionSet(WSManOption[] options) /// public void Dispose() { - if (IntPtr.Zero != _optionSet.options) + if (_optionSet.options != IntPtr.Zero) { Marshal.FreeHGlobal(_optionSet.options); _optionSet.options = IntPtr.Zero; @@ -1174,7 +1174,7 @@ public static implicit operator IntPtr(WSManOptionSet optionSet) /// internal static WSManOptionSet UnMarshal(IntPtr unmanagedData) { - if (IntPtr.Zero == unmanagedData) + if (unmanagedData == IntPtr.Zero) { return new WSManOptionSet(); } @@ -1264,7 +1264,7 @@ internal WSManCommandArgSet(byte[] firstArgument) public void Dispose() { IntPtr firstArgAddress = Marshal.ReadIntPtr(_internalData.args); - if (IntPtr.Zero != firstArgAddress) + if (firstArgAddress != IntPtr.Zero) { Marshal.FreeHGlobal(firstArgAddress); } @@ -1302,7 +1302,7 @@ internal static WSManCommandArgSet UnMarshal(IntPtr unmanagedData) { WSManCommandArgSet result = new WSManCommandArgSet(); - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManCommandArgSetInternal resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -1486,7 +1486,7 @@ internal static WSManShellStartupInfo_UnToMan UnMarshal(IntPtr unmanagedData) { WSManShellStartupInfo_UnToMan result = null; - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManShellStartupInfoStruct resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -1522,7 +1522,7 @@ internal static WSManEnvironmentVariableSet UnMarshal(IntPtr unmanagedData) { WSManEnvironmentVariableSet result = null; - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManEnvironmentVariableSetInternal resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -1841,7 +1841,7 @@ internal static WSManCreateShellDataResult UnMarshal(IntPtr unmanagedData) { WSManCreateShellDataResult result = new WSManCreateShellDataResult(); - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManCreateShellDataResultInternal resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -2058,7 +2058,7 @@ internal static WSManPluginRequest UnMarshal(IntPtr unmanagedData) // Dbg.Assert(IntPtr.Zero != unmanagedData, "unmanagedData must be non-null. This means WinRM sent a bad pointer."); WSManPluginRequest result = null; - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManPluginRequestInternal resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -2116,7 +2116,7 @@ internal static WSManSenderDetails UnMarshal(IntPtr unmanagedData) { WSManSenderDetails result = null; - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManSenderDetailsInternal resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -2169,7 +2169,7 @@ internal static WSManCertificateDetails UnMarshal(IntPtr unmanagedData) { WSManCertificateDetails result = null; - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManCertificateDetailsInternal resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -2218,7 +2218,7 @@ internal static WSManOperationInfo UnMarshal(IntPtr unmanagedData) { WSManOperationInfo result = null; - if (IntPtr.Zero != unmanagedData) + if (unmanagedData != IntPtr.Zero) { WSManOperationInfoInternal resultInternal = Marshal.PtrToStructure(unmanagedData); @@ -2459,15 +2459,15 @@ internal static extern int WSManGetSessionOptionAsDword(IntPtr wsManSessionHandl internal static string WSManGetSessionOptionAsString(IntPtr wsManAPIHandle, WSManSessionOption option) { - Dbg.Assert(IntPtr.Zero != wsManAPIHandle, "wsManAPIHandle cannot be null."); + Dbg.Assert(wsManAPIHandle != IntPtr.Zero, "wsManAPIHandle cannot be null."); // The error code taken from winerror.h used for getting buffer length. const int ERROR_INSUFFICIENT_BUFFER = 122; string returnval = string.Empty; int bufferSize = 0; // calculate buffer size required - if (ERROR_INSUFFICIENT_BUFFER != WSManGetSessionOptionAsString(wsManAPIHandle, - option, 0, null, out bufferSize)) + if (WSManGetSessionOptionAsString(wsManAPIHandle, + option, 0, null, out bufferSize) != ERROR_INSUFFICIENT_BUFFER) { return returnval; } @@ -2805,7 +2805,7 @@ internal static extern void WSManSignalShellEx(IntPtr shellOperationHandle, /// internal static string WSManGetErrorMessage(IntPtr wsManAPIHandle, int errorCode) { - Dbg.Assert(IntPtr.Zero != wsManAPIHandle, "wsManAPIHandle cannot be null."); + Dbg.Assert(wsManAPIHandle != IntPtr.Zero, "wsManAPIHandle cannot be null."); // The error code taken from winerror.h used for getting buffer length. const int ERROR_INSUFFICIENT_BUFFER = 122; @@ -2816,8 +2816,8 @@ internal static string WSManGetErrorMessage(IntPtr wsManAPIHandle, int errorCode string returnval = string.Empty; int bufferSize = 0; // calculate buffer size required - if (ERROR_INSUFFICIENT_BUFFER != WSManGetErrorMessage(wsManAPIHandle, - 0, langCode, errorCode, 0, null, out bufferSize)) + if (WSManGetErrorMessage(wsManAPIHandle, + 0, langCode, errorCode, 0, null, out bufferSize) != ERROR_INSUFFICIENT_BUFFER) { return returnval; } diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs index a8ffc052f4f..ff445fc9e69 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs @@ -333,7 +333,7 @@ internal void CreateShell( if (inboundShellInformation != null) { - if ((uint)WSManNativeApi.WSManDataType.WSMAN_DATA_TYPE_TEXT != inboundShellInformation.Type) + if (inboundShellInformation.Type != (uint)WSManNativeApi.WSManDataType.WSMAN_DATA_TYPE_TEXT) { // only text data is supported ReportOperationComplete( @@ -361,7 +361,7 @@ internal void CreateShell( requestDetails.ToString(), requestDetails.ToString()); result = wsmanPinvokeStatic.WSManPluginReportContext(requestDetails.unmanagedHandle, 0, requestDetails.unmanagedHandle); - if (WSManPluginConstants.ExitCodeSuccess != result) + if (result != WSManPluginConstants.ExitCodeSuccess) { ReportOperationComplete( requestDetails, @@ -563,7 +563,7 @@ private void AddToActiveShellSessions( lock (_syncObject) { IntPtr key = newShellSession.creationRequestDetails.unmanagedHandle; - Dbg.Assert(IntPtr.Zero != key, "NULL handles should not be provided"); + Dbg.Assert(key != IntPtr.Zero, "NULL handles should not be provided"); if (!_activeShellSessions.ContainsKey(key)) { @@ -574,7 +574,7 @@ private void AddToActiveShellSessions( } } - if (-1 != count) + if (count != -1) { // Raise session count changed event WSManServerChannelEvents.RaiseActiveSessionsChangedEvent(new ActiveSessionsChangedEventArgs(count)); @@ -614,7 +614,7 @@ private void DeleteFromActiveShellSessions( } } - if (-1 != count) + if (count != -1) { // Raise session count changed event WSManServerChannelEvents.RaiseActiveSessionsChangedEvent(new ActiveSessionsChangedEventArgs(count)); @@ -662,7 +662,7 @@ private bool validateIncomingContexts( return false; } - if (IntPtr.Zero == shellContext) + if (shellContext == IntPtr.Zero) { ReportOperationComplete( requestDetails, @@ -871,7 +871,7 @@ internal void ConnectShellOrCommand( return; } - if (IntPtr.Zero == commandContext) + if (commandContext == IntPtr.Zero) { mgdShellSession.ExecuteConnect(requestDetails, flags, inboundConnectInformation); return; @@ -964,7 +964,7 @@ internal void SendOneItemToShellOrCommand( return; } - if (IntPtr.Zero == commandContext) + if (commandContext == IntPtr.Zero) { // the data is destined for shell (runspace) session. so let shell handle it mgdShellSession.SendOneItemToSession(requestDetails, flags, stream, inboundData); @@ -1075,7 +1075,7 @@ internal void EnableShellOrCommandToSendDataToClient( "EnableShellOrCommandToSendDataToClient: Instruction destined to shell or for command", string.Empty); - if (IntPtr.Zero == commandContext) + if (commandContext == IntPtr.Zero) { // the instruction is destined for shell (runspace) session. so let shell handle it if (mgdShellSession.EnableSessionToSendDataToClient(requestDetails, flags, streamSet, ctxtToReport)) @@ -1576,7 +1576,7 @@ internal static void PerformWSManPluginSignal( WSManNativeApi.WSManPluginRequest request = WSManNativeApi.WSManPluginRequest.UnMarshal(requestDetails); // Close Command - if (IntPtr.Zero != commandContext) + if (commandContext != IntPtr.Zero) { if (!string.Equals(code, WSManPluginConstants.CtrlCSignal, StringComparison.Ordinal)) { @@ -1640,7 +1640,7 @@ internal static void PerformCloseOperation( return; } - if (IntPtr.Zero == context.commandContext) + if (context.commandContext == IntPtr.Zero) { // this is targeted at shell pluginToUse.CloseShellOperation(context); @@ -1794,13 +1794,13 @@ internal static void SetThreadProperties( WSManPluginConstants.WSManPluginParamsGetRequestedDataLocale, outputStruct); // ref nativeDataLocaleData); - bool retrievingDataLocaleSucceeded = ((int)WSManPluginErrorCodes.NoError == hResult); + bool retrievingDataLocaleSucceeded = (hResult == (int)WSManPluginErrorCodes.NoError); WSManNativeApi.WSManData_UnToMan dataLocaleData = WSManNativeApi.WSManData_UnToMan.UnMarshal(outputStruct); // nativeDataLocaleData // Set the UI Culture try { - if (retrievingLocaleSucceeded && ((uint)WSManNativeApi.WSManDataType.WSMAN_DATA_TYPE_TEXT == localeData.Type)) + if (retrievingLocaleSucceeded && (localeData.Type == (uint)WSManNativeApi.WSManDataType.WSMAN_DATA_TYPE_TEXT)) { CultureInfo uiCultureToUse = new CultureInfo(localeData.Text); Thread.CurrentThread.CurrentUICulture = uiCultureToUse; @@ -1814,7 +1814,7 @@ internal static void SetThreadProperties( // Set the Culture try { - if (retrievingDataLocaleSucceeded && ((uint)WSManNativeApi.WSManDataType.WSMAN_DATA_TYPE_TEXT == dataLocaleData.Type)) + if (retrievingDataLocaleSucceeded && (dataLocaleData.Type == (uint)WSManNativeApi.WSManDataType.WSMAN_DATA_TYPE_TEXT)) { CultureInfo cultureToUse = new CultureInfo(dataLocaleData.Text); Thread.CurrentThread.CurrentCulture = cultureToUse; @@ -1883,7 +1883,7 @@ internal static void ReportOperationComplete( WSManPluginErrorCodes errorCode) { if (requestDetails != null && - IntPtr.Zero != requestDetails.unmanagedHandle) + requestDetails.unmanagedHandle != IntPtr.Zero) { wsmanPinvokeStatic.WSManPluginOperationComplete( requestDetails.unmanagedHandle, @@ -1906,7 +1906,7 @@ internal static void ReportOperationComplete( WSManPluginErrorCodes errorCode, string errorMessage = "") { - if (IntPtr.Zero == requestDetails) + if (requestDetails == IntPtr.Zero) { // cannot report if requestDetails is null. return; diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs index 6735f51b5ca..1c204773d70 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs @@ -433,7 +433,7 @@ private WSManPluginManagedEntryWrapper() { } public static int InitPlugin( IntPtr wkrPtrs) { - if (IntPtr.Zero == wkrPtrs) + if (wkrPtrs == IntPtr.Zero) { return WSManPluginConstants.ExitCodeFailure; } @@ -473,7 +473,7 @@ public static void WSManPluginConnect( IntPtr commandContext, IntPtr inboundConnectInformation) { - if (IntPtr.Zero == pluginContext) + if (pluginContext == IntPtr.Zero) { WSManPluginInstance.ReportOperationComplete( requestDetails, @@ -505,7 +505,7 @@ public static void WSManPluginShell( IntPtr startupInfo, IntPtr inboundShellInformation) { - if (IntPtr.Zero == pluginContext) + if (pluginContext == IntPtr.Zero) { WSManPluginInstance.ReportOperationComplete( requestDetails, @@ -561,7 +561,7 @@ public static void WSManPluginCommand( [MarshalAs(UnmanagedType.LPWStr)] string commandLine, IntPtr arguments) { - if (IntPtr.Zero == pluginContext) + if (pluginContext == IntPtr.Zero) { WSManPluginInstance.ReportOperationComplete( requestDetails, @@ -622,7 +622,7 @@ public static void WSManPluginSend( [MarshalAs(UnmanagedType.LPWStr)] string stream, IntPtr inboundData) { - if (IntPtr.Zero == pluginContext) + if (pluginContext == IntPtr.Zero) { WSManPluginInstance.ReportOperationComplete( requestDetails, @@ -654,7 +654,7 @@ public static void WSManPluginReceive( IntPtr commandContext, IntPtr streamSet) { - if (IntPtr.Zero == pluginContext) + if (pluginContext == IntPtr.Zero) { WSManPluginInstance.ReportOperationComplete( requestDetails, @@ -686,7 +686,7 @@ public static void WSManPluginSignal( IntPtr commandContext, [MarshalAs(UnmanagedType.LPWStr)] string code) { - if ((IntPtr.Zero == pluginContext) || (IntPtr.Zero == shellContext)) + if ((pluginContext == IntPtr.Zero) || (shellContext == IntPtr.Zero)) { WSManPluginInstance.ReportOperationComplete( requestDetails, diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginShellSession.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginShellSession.cs index cf6cdd613df..6df3d25bb86 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginShellSession.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginShellSession.cs @@ -152,7 +152,7 @@ internal void SendOneItemToSession( return; } - if ((uint)WSManNativeApi.WSManDataType.WSMAN_DATA_TYPE_BINARY != inboundData.Type) + if (inboundData.Type != (uint)WSManNativeApi.WSManDataType.WSMAN_DATA_TYPE_BINARY) { // only binary data is supported WSManPluginInstance.ReportOperationComplete( @@ -256,7 +256,7 @@ internal void ReportContext() // TO BE FIXED - As soon as this API is called, WinRM service will send CommandResponse back and Signal is expected anytime // If Signal comes and executes before registering the notification handle, cleanup will be messed result = WSManNativeApi.WSManPluginReportContext(creationRequestDetails.unmanagedHandle, 0, creationRequestDetails.unmanagedHandle); - if (Platform.IsWindows && (WSManPluginConstants.ExitCodeSuccess == result)) + if (Platform.IsWindows && (result == WSManPluginConstants.ExitCodeSuccess)) { registeredShutdownNotification = 1; @@ -281,7 +281,7 @@ internal void ReportContext() } } - if ((WSManPluginConstants.ExitCodeSuccess != result) || (isRegisterWaitForSingleObjectFailed)) + if ((result != WSManPluginConstants.ExitCodeSuccess) || (isRegisterWaitForSingleObjectFailed)) { string errorMessage; if (isRegisterWaitForSingleObjectFailed) @@ -591,7 +591,7 @@ private void AddToActiveCmdSessions( } IntPtr key = newCmdSession.creationRequestDetails.unmanagedHandle; - Dbg.Assert(IntPtr.Zero != key, "NULL handles should not be provided"); + Dbg.Assert(key != IntPtr.Zero, "NULL handles should not be provided"); if (!_activeCommandSessions.ContainsKey(key)) { diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginTransportManager.cs index 312c880b59b..d52ff25c8c2 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginTransportManager.cs @@ -181,7 +181,7 @@ internal override void ReportExecutionStatusAsRunning() } } - if ((int)WSManPluginErrorCodes.NoError != result) + if (result != (int)WSManPluginErrorCodes.NoError) { ReportError(result, "WSManPluginReceiveResult"); } @@ -247,7 +247,7 @@ protected override void SendDataToClient( } } - if ((int)WSManPluginErrorCodes.NoError != result) + if (result != (int)WSManPluginErrorCodes.NoError) { ReportError(result, "WSManPluginReceiveResult"); } diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs index 414020eaa42..67e042f01d1 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs @@ -1203,7 +1203,7 @@ internal override void CloseAsync() else if (_startMode == WSManTransportManagerUtils.tmStartModes.Create || _startMode == WSManTransportManagerUtils.tmStartModes.Connect) { - if (IntPtr.Zero == _wsManShellOperationHandle) + if (_wsManShellOperationHandle == IntPtr.Zero) { shouldRaiseCloseCompleted = true; } @@ -1472,7 +1472,7 @@ private void Initialize(Uri connectionUri, WSManConnectionInfo connectionInfo) proxyAuthCredentials = new WSManNativeApi.WSManUserNameAuthenticationCredentials(userName, password, authMechanism); } - WSManNativeApi.WSManProxyInfo proxyInfo = (ProxyAccessType.None == connectionInfo.ProxyAccessType) ? + WSManNativeApi.WSManProxyInfo proxyInfo = (connectionInfo.ProxyAccessType == ProxyAccessType.None) ? null : new WSManNativeApi.WSManProxyInfo(connectionInfo.ProxyAccessType, proxyAuthCredentials); @@ -1695,7 +1695,7 @@ internal void ClearReceiveOrSendResources(int flags, bool shouldClearSend) } // For send..clear always - if (IntPtr.Zero != _wsManSendOperationHandle) + if (_wsManSendOperationHandle != IntPtr.Zero) { WSManNativeApi.WSManCloseOperation(_wsManSendOperationHandle, 0); _wsManSendOperationHandle = IntPtr.Zero; @@ -1706,7 +1706,7 @@ internal void ClearReceiveOrSendResources(int flags, bool shouldClearSend) // clearing for receive..Clear only when the end of operation is reached. if (flags == (int)WSManNativeApi.WSManCallbackFlags.WSMAN_FLAG_CALLBACK_END_OF_OPERATION) { - if (IntPtr.Zero != _wsManReceiveOperationHandle) + if (_wsManReceiveOperationHandle != IntPtr.Zero) { WSManNativeApi.WSManCloseOperation(_wsManReceiveOperationHandle, 0); _wsManReceiveOperationHandle = IntPtr.Zero; @@ -1894,7 +1894,7 @@ private static void OnCreateSessionCallback(IntPtr operationContext, } } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); @@ -1995,7 +1995,7 @@ private static void OnCloseSessionCompleted(IntPtr operationContext, sessionTM.RunspacePoolInstanceId.ToString(), "OnCloseSessionCompleted"); - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); @@ -2054,7 +2054,7 @@ private static void OnRemoteSessionDisconnectCompleted(IntPtr operationContext, sessionTM._disconnectSessionCompleted = null; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); @@ -2136,7 +2136,7 @@ private static void OnRemoteSessionReconnectCompleted(IntPtr operationContext, sessionTM._reconnectSessionCompleted = null; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); @@ -2246,7 +2246,7 @@ private static void OnRemoteSessionConnectCallback(IntPtr operationContext, return; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); @@ -2353,7 +2353,7 @@ private static void OnRemoteSessionSendCompleted(IntPtr operationContext, return; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); @@ -2423,7 +2423,7 @@ private static void OnRemoteSessionDataReceived(IntPtr operationContext, return; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); @@ -2730,7 +2730,7 @@ public void Dispose() _inputStreamSet.Dispose(); _outputStreamSet.Dispose(); - if (IntPtr.Zero != _handle) + if (_handle != IntPtr.Zero) { int result = 0; @@ -2918,7 +2918,7 @@ internal WSManClientCommandTransportManager(WSManConnectionInfo connectionInfo, WSManClientSessionTransportManager sessnTM) : base(shell, sessnTM.CryptoHelper, sessnTM) { - Dbg.Assert(IntPtr.Zero != wsManShellOperationHandle, "Shell operation handle cannot be IntPtr.Zero."); + Dbg.Assert(wsManShellOperationHandle != IntPtr.Zero, "Shell operation handle cannot be IntPtr.Zero."); Dbg.Assert(connectionInfo != null, "connectionInfo cannot be null"); _wsManShellOperationHandle = wsManShellOperationHandle; @@ -3160,7 +3160,7 @@ internal override void CloseAsync() // There is no valid cmd operation handle..so just // raise close completed. - if (IntPtr.Zero == _wsManCmdOperationHandle) + if (_wsManCmdOperationHandle == IntPtr.Zero) { shouldRaiseCloseCompleted = true; } @@ -3286,7 +3286,7 @@ internal void ClearReceiveOrSendResources(int flags, bool shouldClearSend) } // For send..clear always - if (IntPtr.Zero != _wsManSendOperationHandle) + if (_wsManSendOperationHandle != IntPtr.Zero) { WSManNativeApi.WSManCloseOperation(_wsManSendOperationHandle, 0); _wsManSendOperationHandle = IntPtr.Zero; @@ -3297,7 +3297,7 @@ internal void ClearReceiveOrSendResources(int flags, bool shouldClearSend) // clearing for receive..Clear only when the end of operation is reached. if (flags == (int)WSManNativeApi.WSManCallbackFlags.WSMAN_FLAG_CALLBACK_END_OF_OPERATION) { - if (IntPtr.Zero != _wsManReceiveOperationHandle) + if (_wsManReceiveOperationHandle != IntPtr.Zero) { WSManNativeApi.WSManCloseOperation(_wsManReceiveOperationHandle, 0); _wsManReceiveOperationHandle = IntPtr.Zero; @@ -3386,7 +3386,7 @@ private static void OnCreateCmdCompleted(IntPtr operationContext, // Remove this once WSMan fixes its code. cmdTM._wsManCmdOperationHandle = commandOperationHandle; - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); if (errorStruct.errorCode != 0) @@ -3484,7 +3484,7 @@ private static void OnConnectCmdCompleted(IntPtr operationContext, cmdTM._wsManCmdOperationHandle = commandOperationHandle; - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); if (errorStruct.errorCode != 0) @@ -3655,7 +3655,7 @@ private static void OnRemoteCmdSendCompleted(IntPtr operationContext, return; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); // Ignore Command aborted error. Command aborted is raised by WSMan to @@ -3732,7 +3732,7 @@ private static void OnRemoteCmdDataReceived(IntPtr operationContext, return; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); if (errorStruct.errorCode != 0) @@ -3812,7 +3812,7 @@ private static void OnReconnectCmdCompleted(IntPtr operationContext, return; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); if (errorStruct.errorCode != 0) @@ -3885,7 +3885,7 @@ private static void OnRemoteCmdSignalCompleted(IntPtr operationContext, } // release the resources related to signal - if (IntPtr.Zero != cmdTM._cmdSignalOperationHandle) + if (cmdTM._cmdSignalOperationHandle != IntPtr.Zero) { WSManNativeApi.WSManCloseOperation(cmdTM._cmdSignalOperationHandle, 0); cmdTM._cmdSignalOperationHandle = IntPtr.Zero; @@ -3904,7 +3904,7 @@ private static void OnRemoteCmdSignalCompleted(IntPtr operationContext, return; } - if (IntPtr.Zero != error) + if (error != IntPtr.Zero) { WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error); if (errorStruct.errorCode != 0) diff --git a/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs b/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs index 67817c8c6e2..1c2728cc6d6 100644 --- a/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs +++ b/src/System.Management.Automation/engine/remoting/server/OutOfProcServerMediator.cs @@ -125,7 +125,7 @@ protected void OnDataPacketReceived(byte[] rawData, string stream, Guid psGuid) streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_PROMPTRESPONSE; } - if (Guid.Empty == psGuid) + if (psGuid == Guid.Empty) { lock (_syncObject) { diff --git a/src/System.Management.Automation/engine/serialization.cs b/src/System.Management.Automation/engine/serialization.cs index 488b73d14fc..1f3bbf7fc42 100644 --- a/src/System.Management.Automation/engine/serialization.cs +++ b/src/System.Management.Automation/engine/serialization.cs @@ -540,7 +540,7 @@ private void Start() // If version is not provided, we assume it is the default string version = InternalSerializer.DefaultVersion; - if (DeserializationOptions.NoRootElement == (_context.options & DeserializationOptions.NoRootElement)) + if ((_context.options & DeserializationOptions.NoRootElement) == DeserializationOptions.NoRootElement) { _done = _reader.EOF; } @@ -571,7 +571,7 @@ internal bool Done() { if (!_done) { - if (DeserializationOptions.NoRootElement == (_context.options & DeserializationOptions.NoRootElement)) + if ((_context.options & DeserializationOptions.NoRootElement) == DeserializationOptions.NoRootElement) { _done = _reader.EOF; } @@ -866,7 +866,7 @@ internal TypeTable TypeTable /// internal void Start() { - if (SerializationOptions.NoRootElement != (_context.options & SerializationOptions.NoRootElement)) + if ((_context.options & SerializationOptions.NoRootElement) != SerializationOptions.NoRootElement) { this.WriteStartElement(SerializationStrings.RootElementTag); this.WriteAttribute(SerializationStrings.VersionAttribute, InternalSerializer.DefaultVersion); @@ -878,7 +878,7 @@ internal void Start() /// internal void End() { - if (SerializationOptions.NoRootElement != (_context.options & SerializationOptions.NoRootElement)) + if ((_context.options & SerializationOptions.NoRootElement) != SerializationOptions.NoRootElement) { _writer.WriteEndElement(); } @@ -2750,7 +2750,7 @@ internal static void WriteSecureString(InternalSerializer serializer, string str private void WriteStartElement(string elementTag) { Dbg.Assert(!string.IsNullOrEmpty(elementTag), "Caller should validate the parameter"); - if (SerializationOptions.NoNamespace == (_context.options & SerializationOptions.NoNamespace)) + if ((_context.options & SerializationOptions.NoNamespace) == SerializationOptions.NoNamespace) { _writer.WriteStartElement(elementTag); } @@ -2908,7 +2908,7 @@ private void WriteEncodedElementString(string name, string value) value = EncodeString(value); - if (SerializationOptions.NoNamespace == (_context.options & SerializationOptions.NoNamespace)) + if ((_context.options & SerializationOptions.NoNamespace) == SerializationOptions.NoNamespace) { _writer.WriteElementString(name, value); } @@ -4418,7 +4418,7 @@ internal static object DeserializeScriptBlock(InternalDeserializer deserializer) { Dbg.Assert(deserializer != null, "Caller should validate the parameter"); string scriptBlockBody = deserializer.ReadDecodedElementString(SerializationStrings.ScriptBlockTag); - if (DeserializationOptions.DeserializeScriptBlocks == (deserializer._context.options & DeserializationOptions.DeserializeScriptBlocks)) + if ((deserializer._context.options & DeserializationOptions.DeserializeScriptBlocks) == DeserializationOptions.DeserializeScriptBlocks) { return ScriptBlock.Create(scriptBlockBody); } @@ -4768,7 +4768,7 @@ private void ReadStartElement(string element) { Dbg.Assert(!string.IsNullOrEmpty(element), "Caller should validate the parameter"); - if (DeserializationOptions.NoNamespace == (_context.options & DeserializationOptions.NoNamespace)) + if ((_context.options & DeserializationOptions.NoNamespace) == DeserializationOptions.NoNamespace) { _reader.ReadStartElement(element); } @@ -4792,7 +4792,7 @@ private string ReadDecodedElementString(string element) this.CheckIfStopping(); string temp = null; - if (DeserializationOptions.NoNamespace == (_context.options & DeserializationOptions.NoNamespace)) + if ((_context.options & DeserializationOptions.NoNamespace) == DeserializationOptions.NoNamespace) { temp = _reader.ReadElementContentAsString(element, string.Empty); } @@ -6850,14 +6850,14 @@ internal static T GetPropertyValue(PSObject pso, string propertyName, Rehydra Dbg.Assert(!string.IsNullOrEmpty(propertyName), "Caller should verify propertyName != null"); PSPropertyInfo property = pso.Properties[propertyName]; - if ((property == null) && (RehydrationFlags.MissingPropertyOk == (flags & RehydrationFlags.MissingPropertyOk))) + if ((property == null) && ((flags & RehydrationFlags.MissingPropertyOk) == RehydrationFlags.MissingPropertyOk)) { return default(T); } else { object propertyValue = property.Value; - if ((propertyValue == null) && (RehydrationFlags.NullValueOk == (flags & RehydrationFlags.NullValueOk))) + if ((propertyValue == null) && ((flags & RehydrationFlags.NullValueOk) == RehydrationFlags.NullValueOk)) { return default(T); } @@ -6875,7 +6875,7 @@ private static ListType RehydrateList(PSObject pso, string p ArrayList deserializedList = GetPropertyValue(pso, propertyName, flags); if (deserializedList == null) { - if (RehydrationFlags.NullValueMeansEmptyList == (flags & RehydrationFlags.NullValueMeansEmptyList)) + if ((flags & RehydrationFlags.NullValueMeansEmptyList) == RehydrationFlags.NullValueMeansEmptyList) { return new ListType(); } diff --git a/src/System.Management.Automation/help/CabinetNativeApi.cs b/src/System.Management.Automation/help/CabinetNativeApi.cs index 267317b11d0..acc5bddcf6e 100644 --- a/src/System.Management.Automation/help/CabinetNativeApi.cs +++ b/src/System.Management.Automation/help/CabinetNativeApi.cs @@ -458,11 +458,11 @@ internal static FileMode ConvertOpflagToFileMode(int oflag) { // Note: This is not done in a switch because the order of tests matters. - if ((int)(OpFlags.Create | OpFlags.Excl) == (oflag & (int)(OpFlags.Create | OpFlags.Excl))) + if ((oflag & (int)(OpFlags.Create | OpFlags.Excl)) == (int)(OpFlags.Create | OpFlags.Excl)) { return FileMode.CreateNew; } - else if ((int)(OpFlags.Create | OpFlags.Truncate) == (oflag & (int)(OpFlags.Create | OpFlags.Truncate))) + else if ((oflag & (int)(OpFlags.Create | OpFlags.Truncate)) == (int)(OpFlags.Create | OpFlags.Truncate)) { return FileMode.OpenOrCreate; } @@ -497,7 +497,7 @@ internal static FileAccess ConvertPermissionModeToFileAccess(int pmode) { // Note: This is not done in a switch because the order of tests matters. - if ((int)(PermissionMode.Read | PermissionMode.Write) == (pmode & (int)(PermissionMode.Read | PermissionMode.Write))) + if ((pmode & (int)(PermissionMode.Read | PermissionMode.Write)) == (int)(PermissionMode.Read | PermissionMode.Write)) { return FileAccess.ReadWrite; } @@ -524,7 +524,7 @@ internal static FileShare ConvertPermissionModeToFileShare(int pmode) { // Note: This is not done in a switch because the order of tests matters. - if ((int)(PermissionMode.Read | PermissionMode.Write) == (pmode & (int)(PermissionMode.Read | PermissionMode.Write))) + if ((pmode & (int)(PermissionMode.Read | PermissionMode.Write)) == (int)(PermissionMode.Read | PermissionMode.Write)) { return FileShare.ReadWrite; } diff --git a/src/System.Management.Automation/security/nativeMethods.cs b/src/System.Management.Automation/security/nativeMethods.cs index e6ca212c274..6040e075a4a 100644 --- a/src/System.Management.Automation/security/nativeMethods.cs +++ b/src/System.Management.Automation/security/nativeMethods.cs @@ -1877,7 +1877,7 @@ internal static bool IsSystem32DllPresent(string DllName) NativeMethods.LOAD_LIBRARY_AS_DATAFILE | NativeMethods.LOAD_LIBRARY_AS_IMAGE_RESOURCE | NativeMethods.LOAD_LIBRARY_SEARCH_SYSTEM32); - if (IntPtr.Zero != module) + if (module != IntPtr.Zero) { FreeLibrary(module); DllExists = true; diff --git a/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs b/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs index 81b011d389a..e08d8e1a65c 100644 --- a/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs +++ b/src/System.Management.Automation/utils/CommandDiscoveryExceptions.cs @@ -161,7 +161,7 @@ params object[] messageArgs ) { object[] a; - if (messageArgs != null && 0 < messageArgs.Length) + if (messageArgs != null && messageArgs.Length > 0) { a = new object[messageArgs.Length + 1]; a[0] = commandName; diff --git a/src/System.Management.Automation/utils/ObjectStream.cs b/src/System.Management.Automation/utils/ObjectStream.cs index 807292fd3d8..2f4cbef8a08 100644 --- a/src/System.Management.Automation/utils/ObjectStream.cs +++ b/src/System.Management.Automation/utils/ObjectStream.cs @@ -1403,7 +1403,7 @@ internal override int Write(object obj, bool enumerateCollection) // subtraction to ensure we don't have an // overflow exception int freeSpace = _capacity - _objects.Count; - if (0 >= freeSpace) + if (freeSpace <= 0) { // NOTE: lock is released in finally continue; diff --git a/src/System.Management.Automation/utils/SessionStateExceptions.cs b/src/System.Management.Automation/utils/SessionStateExceptions.cs index b8b79af68a6..a08e7615dc5 100644 --- a/src/System.Management.Automation/utils/SessionStateExceptions.cs +++ b/src/System.Management.Automation/utils/SessionStateExceptions.cs @@ -543,7 +543,7 @@ private static string BuildMessage( params object[] messageArgs) { object[] a; - if (messageArgs != null && 0 < messageArgs.Length) + if (messageArgs != null && messageArgs.Length > 0) { a = new object[messageArgs.Length + 1]; a[0] = itemName;