diff --git a/.globalconfig b/.globalconfig index 33d6fe31e7e..0193c97f247 100644 --- a/.globalconfig +++ b/.globalconfig @@ -886,7 +886,7 @@ dotnet_diagnostic.IDE0052.severity = silent dotnet_diagnostic.IDE0053.severity = silent # IDE0054: UseCompoundAssignment -dotnet_diagnostic.IDE0054.severity = silent +dotnet_diagnostic.IDE0054.severity = warning # IDE0055: Formatting dotnet_diagnostic.IDE0055.severity = silent diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 5397731bca4..0f5443da4ad 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -2505,7 +2505,7 @@ private Process StartWithCreateProcess(ProcessStartInfo startinfo) message = StringUtil.Format(ProcessResources.InvalidStartProcess, win32ex.Message); } - er = er ?? new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null); + er ??= new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null); ThrowTerminatingError(er); } diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetClipboardCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetClipboardCommand.cs index 4c8a7c36c7b..42a4624d5dd 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/SetClipboardCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/SetClipboardCommand.cs @@ -102,7 +102,7 @@ private void SetClipboardContent(List contentList, bool append) if (verboseString.Length >= 20) { verboseString = verboseString.Substring(0, 20); - verboseString = verboseString + " ..."; + verboseString += " ..."; } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs index 2ea6d6e20ae..33f2f44f063 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs @@ -388,7 +388,7 @@ protected override void ProcessRecord() memberCount++; } - memberCountHelper = memberCountHelper >> 1; + memberCountHelper >>= 1; } if (memberCount != 1) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs index 7b10beaa412..8830a6793eb 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs @@ -334,7 +334,7 @@ private double GetRandomDouble(double minValue, double maxValue) { double r = Generator.NextDouble(); randomNumber = minValue + r * diff; - diff = diff * r; + diff *= r; } while (randomNumber >= maxValue); } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs index e8c95c484c0..d43a9a42ae0 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs @@ -2430,7 +2430,7 @@ private void GenerateHelperFunctionsGetImplicitRunspace(TextWriter writer) out hashString, ImplicitRemotingCommandBase.ImplicitRemotingKey, ImplicitRemotingCommandBase.ImplicitRemotingHashKey); - hashString = hashString ?? string.Empty; + hashString ??= string.Empty; writer.Write( HelperFunctionsGetImplicitRunspaceTemplate, diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index 379dddf06cd..01b3c7ef85f 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -2670,19 +2670,19 @@ private CertificateFilterInfo GetFilter() if (dp.DocumentEncryptionCert) { - filter = filter ?? new CertificateFilterInfo(); + filter ??= new CertificateFilterInfo(); filter.Purpose = CertificatePurpose.DocumentEncryption; } if (dp.DnsName != null) { - filter = filter ?? new CertificateFilterInfo(); + filter ??= new CertificateFilterInfo(); filter.DnsName = new WildcardPattern(dp.DnsName, WildcardOptions.IgnoreCase); } if (dp.Eku != null) { - filter = filter ?? new CertificateFilterInfo(); + filter ??= new CertificateFilterInfo(); filter.Eku = new List(); foreach (var pattern in dp.Eku) { @@ -2692,13 +2692,13 @@ private CertificateFilterInfo GetFilter() if (dp.ExpiringInDays >= 0) { - filter = filter ?? new CertificateFilterInfo(); + filter ??= new CertificateFilterInfo(); filter.Expiring = DateTime.Now.AddDays(dp.ExpiringInDays); } if (dp.SSLServerAuthentication) { - filter = filter ?? new CertificateFilterInfo(); + filter ??= new CertificateFilterInfo(); filter.SSLServerAuthentication = true; } } diff --git a/src/Microsoft.PowerShell.Security/security/CmsCommands.cs b/src/Microsoft.PowerShell.Security/security/CmsCommands.cs index c879ac74a05..3e4a31f2a0d 100644 --- a/src/Microsoft.PowerShell.Security/security/CmsCommands.cs +++ b/src/Microsoft.PowerShell.Security/security/CmsCommands.cs @@ -577,7 +577,7 @@ private string Decrypt(string actualContent) if (postContext != null) { - resultString = resultString + postContext; + resultString += postContext; } } diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index 8f0b7f87a07..7726d000bf1 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -439,7 +439,7 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether it has Chi // 3. Plugin and its internal structure Checks else if (WsManURI.Contains(WSManStringLiterals.containerPlugin)) { - strPathCheck = strPathCheck + WSManStringLiterals.containerPlugin; + strPathCheck += WSManStringLiterals.containerPlugin; // Check for Plugin path XmlDocument xmlPlugins = FindResourceValue(sessionobj, WsManURI, null); string currentpluginname = string.Empty; @@ -477,7 +477,7 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether it has Chi ArrayList arrSecurities = null; ArrayList arrResources = ProcessPluginResourceLevel(CurrentPluginXML, out arrSecurities); ArrayList arrInitParams = ProcessPluginInitParamLevel(CurrentPluginXML); - strPathCheck = strPathCheck + WSManStringLiterals.DefaultPathSeparator; + strPathCheck += WSManStringLiterals.DefaultPathSeparator; if (path.EndsWith(strPathCheck + WSManStringLiterals.containerResources, StringComparison.OrdinalIgnoreCase)) { if (arrResources != null && arrResources.Count > 0) @@ -1473,7 +1473,7 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether Item is Co strPathCheck = host + WSManStringLiterals.DefaultPathSeparator; if (WsManURI.Contains(WSManStringLiterals.containerListener)) { - strPathCheck = strPathCheck + WSManStringLiterals.containerListener; + strPathCheck += WSManStringLiterals.containerListener; if (path.EndsWith(strPathCheck, StringComparison.OrdinalIgnoreCase)) { return true; @@ -1494,7 +1494,7 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether Item is Co // 2. Client Certificate Checks else if (WsManURI.Contains(WSManStringLiterals.containerCertMapping)) { - strPathCheck = strPathCheck + WSManStringLiterals.containerClientCertificate; + strPathCheck += WSManStringLiterals.containerClientCertificate; if (path.EndsWith(strPathCheck, StringComparison.OrdinalIgnoreCase)) { return true; @@ -1514,19 +1514,19 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether Item is Co // 3. Plugin and its internal structure Checks else if (WsManURI.Contains(WSManStringLiterals.containerPlugin)) { - strPathCheck = strPathCheck + WSManStringLiterals.containerPlugin; + strPathCheck += WSManStringLiterals.containerPlugin; // Check for Plugin path if (path.EndsWith(strPathCheck, StringComparison.OrdinalIgnoreCase)) { return true; } - strPathCheck = strPathCheck + WSManStringLiterals.DefaultPathSeparator; + strPathCheck += WSManStringLiterals.DefaultPathSeparator; XmlDocument xmlPlugins = FindResourceValue(sessionobj, WsManURI, null); string currentpluginname = string.Empty; GetPluginNames(xmlPlugins, out objPluginNames, out currentpluginname, path); - strPathCheck = strPathCheck + currentpluginname; + strPathCheck += currentpluginname; if (path.EndsWith(currentpluginname, StringComparison.OrdinalIgnoreCase)) { return true; @@ -1541,7 +1541,7 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether Item is Co return true; } - strPathCheck = strPathCheck + WSManStringLiterals.DefaultPathSeparator; + strPathCheck += WSManStringLiterals.DefaultPathSeparator; if (path.EndsWith(strPathCheck + WSManStringLiterals.containerResources, StringComparison.OrdinalIgnoreCase)) { return true; @@ -1695,7 +1695,7 @@ protected override void RemoveItem(string path, bool recurse) return; } - strPathCheck = strPathCheck + WSManStringLiterals.containerPlugin; + strPathCheck += WSManStringLiterals.containerPlugin; int pos = 0; string pName = null; pos = path.LastIndexOf(strPathCheck + WSManStringLiterals.DefaultPathSeparator, StringComparison.OrdinalIgnoreCase) + strPathCheck.Length + 1; @@ -2152,7 +2152,7 @@ private void NewItemPluginOrPluginChild(object sessionobj, string path, string h strPathChk = strPathChk + WSManStringLiterals.DefaultPathSeparator + pName + WSManStringLiterals.DefaultPathSeparator; if (path.Contains(strPathChk + WSManStringLiterals.containerResources)) { - strPathChk = strPathChk + WSManStringLiterals.containerResources; + strPathChk += WSManStringLiterals.containerResources; if (path.EndsWith(strPathChk, StringComparison.OrdinalIgnoreCase)) { WSManProviderNewItemResourceParameters niParams = DynamicParameters as WSManProviderNewItemResourceParameters; @@ -2768,7 +2768,7 @@ private XmlDocument EnumerateResourceValue(object sessionobj, string ResourceURI while (!((IWSManEnumerator)value).AtEndOfStream) { - strXmlValue = strXmlValue + ((IWSManEnumerator)value).ReadItem(); + strXmlValue += ((IWSManEnumerator)value).ReadItem(); } Marshal.ReleaseComObject(value); @@ -2900,7 +2900,7 @@ private bool ContainResourceValue(object sessionobj, string ResourceURI, string while (!((IWSManEnumerator)value).AtEndOfStream) { - valuexml = valuexml + ((IWSManEnumerator)value).ReadItem(); + valuexml += ((IWSManEnumerator)value).ReadItem(); } if ((valuexml != string.Empty) && !(string.IsNullOrEmpty(valuexml))) diff --git a/src/Microsoft.WSMan.Management/WSManInstance.cs b/src/Microsoft.WSMan.Management/WSManInstance.cs index 21ae0d1f0fe..a8eaad6ab9a 100644 --- a/src/Microsoft.WSMan.Management/WSManInstance.cs +++ b/src/Microsoft.WSMan.Management/WSManInstance.cs @@ -413,7 +413,7 @@ private string GetFilter() filter = filter + "" + value + ""; } - filter = filter + ""; + filter += ""; return (filter); } diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index e89f8b43e54..ef29cb1a5c2 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -562,7 +562,7 @@ internal IWSManResourceLocator InitializeResourceLocator(Hashtable optionset, Ha if (selectorset != null) { - resource = resource + "?"; + resource += "?"; int i = 0; foreach (DictionaryEntry entry in selectorset) { @@ -656,7 +656,7 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM { if (authentication.Equals(AuthenticationMechanism.None)) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseNoAuthentication; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUseNoAuthentication; } if (authentication.Equals(AuthenticationMechanism.Basic)) @@ -666,12 +666,12 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM if (authentication.Equals(AuthenticationMechanism.Negotiate)) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseNegotiate; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUseNegotiate; } if (authentication.Equals(AuthenticationMechanism.Kerberos)) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseKerberos; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUseKerberos; } if (authentication.Equals(AuthenticationMechanism.Digest)) @@ -686,7 +686,7 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM if (authentication.Equals(AuthenticationMechanism.ClientCertificate)) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseClientCertificate; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUseClientCertificate; } } @@ -718,7 +718,7 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM connObject.Password = nwCredential.Password; if (!authentication.Equals(AuthenticationMechanism.Credssp) || !authentication.Equals(AuthenticationMechanism.Digest) || authentication.Equals(AuthenticationMechanism.Basic)) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagCredUserNamePassword; + sessionFlags |= (int)WSManSessionFlags.WSManFlagCredUserNamePassword; } } } @@ -726,7 +726,7 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM if (certificateThumbprint != null) { connObject.CertificateThumbprint = certificateThumbprint; - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseClientCertificate; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUseClientCertificate; } if (sessionoption != null) @@ -784,48 +784,48 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM if (sessionoption.SkipCACheck) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagSkipCACheck; + sessionFlags |= (int)WSManSessionFlags.WSManFlagSkipCACheck; } if (sessionoption.SkipCNCheck) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagSkipCNCheck; + sessionFlags |= (int)WSManSessionFlags.WSManFlagSkipCNCheck; } if (sessionoption.SPNPort > 0) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagEnableSpnServerPort; + sessionFlags |= (int)WSManSessionFlags.WSManFlagEnableSpnServerPort; } if (sessionoption.UseUtf16) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUtf16; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUtf16; } else { // If UseUtf16 is false, then default Encoding is Utf8 - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUtf8; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUtf8; } if (!sessionoption.UseEncryption) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagNoEncryption; + sessionFlags |= (int)WSManSessionFlags.WSManFlagNoEncryption; } if (sessionoption.SkipRevocationCheck) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagSkipRevocationCheck; + sessionFlags |= (int)WSManSessionFlags.WSManFlagSkipRevocationCheck; } } else { // If SessionOption is null then, default Encoding is Utf8 - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUtf8; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUtf8; } if (usessl) { - sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseSsl; + sessionFlags |= (int)WSManSessionFlags.WSManFlagUseSsl; } IWSManSession m_SessionObj = null; diff --git a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs index eeccc290883..a9afe8f004e 100644 --- a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs +++ b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs @@ -4119,7 +4119,7 @@ private bool BindPipelineParameter( /*argumentAst*/null, parameterValue, false); - flags = flags & ~ParameterBindingFlags.DelayBindScriptBlock; + flags &= ~ParameterBindingFlags.DelayBindScriptBlock; result = BindParameter(_currentParameterSetFlag, param, parameter, flags); if (result) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs index e00e0d737fc..ce696f63033 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs @@ -891,7 +891,7 @@ internal static List PSv2GenerateMatchSetOfFiles(PowerShellExe // Determine if we need to quote the paths we parse - lastWord = lastWord ?? string.Empty; + lastWord ??= string.Empty; bool isLastWordEmpty = string.IsNullOrEmpty(lastWord); bool lastCharIsStar = !isLastWordEmpty && lastWord.EndsWith('*'); bool containsGlobChars = WildcardPattern.ContainsWildcardCharacters(lastWord); diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs index ead7a85ec4f..f3347cdf4f0 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs @@ -1443,7 +1443,7 @@ private List GetResultForEnumPropertyValueOfDSCResource( { string completionText = isCursorInString ? value : stringQuote + value + stringQuote; if (hasNewLine) - completionText = completionText + stringQuote; + completionText += stringQuote; result.Add(new CompletionResult( completionText, value, @@ -1494,7 +1494,7 @@ private List GetResultForEnumPropertyValueOfDSCResource( { string completionText = isCursorInString ? resource : stringQuote + resource + stringQuote; if (hasNewLine) - completionText = completionText + stringQuote; + completionText += stringQuote; result.Add(new CompletionResult( completionText, resource, diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 45d33d895d9..27c93412e2d 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -3630,7 +3630,7 @@ private static void NativeCompletionSetLocationCommand(CompletionContext context RemoveLastNullCompletionResult(result); - context.WordToComplete = context.WordToComplete ?? string.Empty; + context.WordToComplete ??= string.Empty; var clearLiteralPath = false; if (paramName.Equals("LiteralPath", StringComparison.OrdinalIgnoreCase)) { @@ -3736,7 +3736,7 @@ private static void NativeCompletionCopyMoveItemCommand(CompletionContext contex // The parameter Destination for Move-Item and Copy-Item takes literal path RemoveLastNullCompletionResult(result); - context.WordToComplete = context.WordToComplete ?? string.Empty; + context.WordToComplete ??= string.Empty; var clearLiteralPath = TurnOnLiteralPathOption(context); try @@ -3767,7 +3767,7 @@ private static void NativeCompletionPathArgument(CompletionContext context, stri RemoveLastNullCompletionResult(result); - context.WordToComplete = context.WordToComplete ?? string.Empty; + context.WordToComplete ??= string.Empty; var clearLiteralPath = false; if (paramName.Equals("LiteralPath", StringComparison.OrdinalIgnoreCase)) { @@ -4259,7 +4259,7 @@ internal static IEnumerable CompleteFilename(CompletionContext if (leaf != null) { - leaf = leaf + "*"; + leaf += "*"; var parentPath = Path.GetDirectoryName(providerPath); // ProviderPath should be absolute path for FileSystem entries diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index b98999cae65..2872066e74d 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1151,12 +1151,12 @@ private void InitializeMembers() _bindableParameters = null; // reuse the collections/dictionaries - _arguments = _arguments ?? new Collection(); - _boundParameters = _boundParameters ?? new Dictionary(StringComparer.OrdinalIgnoreCase); - _boundArguments = _boundArguments ?? new Dictionary(StringComparer.OrdinalIgnoreCase); - _unboundParameters = _unboundParameters ?? new List(); - _boundPositionalParameter = _boundPositionalParameter ?? new Collection(); - _bindingExceptions = _bindingExceptions ?? new Dictionary(); + _arguments ??= new Collection(); + _boundParameters ??= new Dictionary(StringComparer.OrdinalIgnoreCase); + _boundArguments ??= new Dictionary(StringComparer.OrdinalIgnoreCase); + _unboundParameters ??= new List(); + _boundPositionalParameter ??= new Collection(); + _bindingExceptions ??= new Dictionary(); _arguments.Clear(); _boundParameters.Clear(); @@ -1171,9 +1171,9 @@ private void InitializeMembers() _isPipelineInputExpected = false; // reuse the collections - _parametersNotFound = _parametersNotFound ?? new Collection(); - _ambiguousParameters = _ambiguousParameters ?? new Collection(); - _duplicateParameters = _duplicateParameters ?? new Collection(); + _parametersNotFound ??= new Collection(); + _ambiguousParameters ??= new Collection(); + _duplicateParameters ??= new Collection(); _parametersNotFound.Clear(); _ambiguousParameters.Clear(); diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index f5f2a0501f0..9153cd3deda 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -652,7 +652,7 @@ internal static void ShouldRun(ExecutionContext context, PSHost host, CommandInf private static CommandProcessorBase CreateCommandProcessorForScript(ScriptInfo scriptInfo, ExecutionContext context, bool useNewScope, SessionStateInternal sessionState) { - sessionState = sessionState ?? scriptInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState; + sessionState ??= scriptInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState; CommandProcessorBase scriptAsCmdletProcessor = GetScriptAsCmdletProcessor(scriptInfo, context, useNewScope, true, sessionState); if (scriptAsCmdletProcessor != null) { @@ -664,7 +664,7 @@ private static CommandProcessorBase CreateCommandProcessorForScript(ScriptInfo s private static CommandProcessorBase CreateCommandProcessorForScript(ExternalScriptInfo scriptInfo, ExecutionContext context, bool useNewScope, SessionStateInternal sessionState) { - sessionState = sessionState ?? scriptInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState; + sessionState ??= scriptInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState; CommandProcessorBase scriptAsCmdletProcessor = GetScriptAsCmdletProcessor(scriptInfo, context, useNewScope, true, sessionState); if (scriptAsCmdletProcessor != null) { @@ -676,7 +676,7 @@ private static CommandProcessorBase CreateCommandProcessorForScript(ExternalScri internal static CommandProcessorBase CreateCommandProcessorForScript(FunctionInfo functionInfo, ExecutionContext context, bool useNewScope, SessionStateInternal sessionState) { - sessionState = sessionState ?? functionInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState; + sessionState ??= functionInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState; CommandProcessorBase scriptAsCmdletProcessor = GetScriptAsCmdletProcessor(functionInfo, context, useNewScope, false, sessionState); if (scriptAsCmdletProcessor != null) { @@ -688,7 +688,7 @@ internal static CommandProcessorBase CreateCommandProcessorForScript(FunctionInf internal static CommandProcessorBase CreateCommandProcessorForScript(ScriptBlock scriptblock, ExecutionContext context, bool useNewScope, SessionStateInternal sessionState) { - sessionState = sessionState ?? scriptblock.SessionStateInternal ?? context.EngineSessionState; + sessionState ??= scriptblock.SessionStateInternal ?? context.EngineSessionState; if (scriptblock.UsesCmdletBinding) { @@ -706,7 +706,7 @@ private static CommandProcessorBase GetScriptAsCmdletProcessor(IScriptCommandInf return null; } - sessionState = sessionState ?? scriptCommandInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState; + sessionState ??= scriptCommandInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState; return new CommandProcessor(scriptCommandInfo, context, useNewScope, fromScriptFile, sessionState); } diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 8cdd7b6f076..111218e220d 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -5244,12 +5244,12 @@ private static void AnalyzeModuleAssemblyWithReflection( cmdlet.SetModule(moduleInfo); } - cmdlets = cmdlets ?? new Dictionary(StringComparer.OrdinalIgnoreCase); + cmdlets ??= new Dictionary(StringComparer.OrdinalIgnoreCase); cmdlets.Add(cmdletName, cmdlet); if (TryGetCustomAttribute(type, out AliasAttribute aliasAttribute)) { - aliases = aliases ?? new Dictionary>(StringComparer.OrdinalIgnoreCase); + aliases ??= new Dictionary>(StringComparer.OrdinalIgnoreCase); var aliasList = new List(); foreach (var alias in aliasAttribute.AliasNames) @@ -5302,7 +5302,7 @@ private static void AnalyzeModuleAssemblyWithReflection( provider.SetModule(moduleInfo); } - providers = providers ?? new Dictionary(StringComparer.OrdinalIgnoreCase); + providers ??= new Dictionary(StringComparer.OrdinalIgnoreCase); providers.Add(providerName, provider); s_PSSnapInTracer.WriteLine("{0} from type {1} is added as a provider. ", providerName, type.FullName); diff --git a/src/System.Management.Automation/engine/MinishellParameterBinderController.cs b/src/System.Management.Automation/engine/MinishellParameterBinderController.cs index 4bf375e7c99..cff18352780 100644 --- a/src/System.Management.Automation/engine/MinishellParameterBinderController.cs +++ b/src/System.Management.Automation/engine/MinishellParameterBinderController.cs @@ -271,7 +271,7 @@ private void HandleSeenParameter(ref MinishellParameters seen, MinishellParamete } else { - seen = seen | parameter; + seen |= parameter; } } diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index a70ac75dfc5..c83ddc2076b 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -1144,7 +1144,7 @@ internal static Version GetMaximumVersion(string stringVersion) if (stringVersion[stringVersion.Length - 1] == '*') { stringVersion = stringVersion.Substring(0, stringVersion.Length - 1); - stringVersion = stringVersion + maxRange; + stringVersion += maxRange; int starNum = stringVersion.Count(x => x == '.'); for (int i = 0; i < (3 - starNum); i++) { diff --git a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs index 015b2bb72d2..cd4cb677979 100644 --- a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs +++ b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs @@ -744,7 +744,7 @@ internal static IEnumerable GetCimModules( Cmdlet cmdlet, CancellationToken cancellationToken) { - moduleNamePatterns = moduleNamePatterns ?? new[] { "*" }; + moduleNamePatterns ??= new[] { "*" }; HashSet alreadyEmittedNamesOfCimModules = new HashSet(StringComparer.OrdinalIgnoreCase); IEnumerable remoteModules = moduleNamePatterns @@ -855,9 +855,9 @@ internal static Hashtable RewriteManifest( IEnumerable typesToProcess, IEnumerable formatsToProcess) { - nestedModules = nestedModules ?? Array.Empty(); - typesToProcess = typesToProcess ?? Array.Empty(); - formatsToProcess = formatsToProcess ?? Array.Empty(); + nestedModules ??= Array.Empty(); + typesToProcess ??= Array.Empty(); + formatsToProcess ??= Array.Empty(); var newManifest = new Hashtable(StringComparer.OrdinalIgnoreCase); newManifest["NestedModules"] = nestedModules; @@ -1037,7 +1037,7 @@ internal static Hashtable ConvertCimModuleFileToManifestHashtable(RemoteDiscover internal static string GetModulePath(string remoteModuleName, Version remoteModuleVersion, string computerName, Runspace localRunspace) { - computerName = computerName ?? string.Empty; + computerName ??= string.Empty; string sanitizedRemoteModuleName = Regex.Replace(remoteModuleName, "[^a-zA-Z0-9]", string.Empty); string sanitizedComputerName = Regex.Replace(computerName, "[^a-zA-Z0-9]", string.Empty); diff --git a/src/System.Management.Automation/engine/ParameterBinderController.cs b/src/System.Management.Automation/engine/ParameterBinderController.cs index e62454622ed..ed2b107b214 100644 --- a/src/System.Management.Automation/engine/ParameterBinderController.cs +++ b/src/System.Management.Automation/engine/ParameterBinderController.cs @@ -459,7 +459,7 @@ internal virtual bool BindParameter( throw bindingException; } - flags = flags & ~ParameterBindingFlags.DelayBindScriptBlock; + flags &= ~ParameterBindingFlags.DelayBindScriptBlock; result = BindParameter(_currentParameterSetFlag, argument, matchingParameter, flags); } diff --git a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs index 9b4028314b8..f63a0a87c0f 100644 --- a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs @@ -1179,7 +1179,7 @@ internal object SetVariable( if (variablePath.IsPrivate && varResult != null) { - varResult.Options = varResult.Options | ScopedItemOptions.Private; + varResult.Options |= ScopedItemOptions.Private; } result = varResult; diff --git a/src/System.Management.Automation/engine/TypeMetadata.cs b/src/System.Management.Automation/engine/TypeMetadata.cs index 192042a3def..f9a354d04f0 100644 --- a/src/System.Management.Automation/engine/TypeMetadata.cs +++ b/src/System.Management.Automation/engine/TypeMetadata.cs @@ -265,13 +265,13 @@ internal ParameterFlags Flags get { ParameterFlags flags = 0; - if (IsMandatory) { flags = flags | ParameterFlags.Mandatory; } + if (IsMandatory) { flags |= ParameterFlags.Mandatory; } - if (ValueFromPipeline) { flags = flags | ParameterFlags.ValueFromPipeline; } + if (ValueFromPipeline) { flags |= ParameterFlags.ValueFromPipeline; } - if (ValueFromPipelineByPropertyName) { flags = flags | ParameterFlags.ValueFromPipelineByPropertyName; } + if (ValueFromPipelineByPropertyName) { flags |= ParameterFlags.ValueFromPipelineByPropertyName; } - if (ValueFromRemainingArguments) { flags = flags | ParameterFlags.ValueFromRemainingArguments; } + if (ValueFromRemainingArguments) { flags |= ParameterFlags.ValueFromRemainingArguments; } return flags; } diff --git a/src/System.Management.Automation/engine/hostifaces/Parameter.cs b/src/System.Management.Automation/engine/hostifaces/Parameter.cs index 725cc93e022..7839af452b6 100644 --- a/src/System.Management.Automation/engine/hostifaces/Parameter.cs +++ b/src/System.Management.Automation/engine/hostifaces/Parameter.cs @@ -101,7 +101,7 @@ internal static CommandParameter FromCommandParameterInternal(CommandParameterIn name = internalParameter.ParameterText; if (internalParameter.SpaceAfterParameter) { - name = name + " "; + name += " "; } Diagnostics.Assert(name != null, "'name' variable should be initialized at this point"); diff --git a/src/System.Management.Automation/engine/interpreter/LightCompiler.cs b/src/System.Management.Automation/engine/interpreter/LightCompiler.cs index e5d399bf480..e938b8e3747 100644 --- a/src/System.Management.Automation/engine/interpreter/LightCompiler.cs +++ b/src/System.Management.Automation/engine/interpreter/LightCompiler.cs @@ -221,7 +221,7 @@ public static DebugInfo GetMatchingDebugInfo(DebugInfo[] debugInfos, int index) return null; } // return the last one that is smaller - i = i - 1; + i -= 1; } return debugInfos[i]; diff --git a/src/System.Management.Automation/engine/parser/Compiler.cs b/src/System.Management.Automation/engine/parser/Compiler.cs index 5c75bfe40f8..8bfada27aa5 100644 --- a/src/System.Management.Automation/engine/parser/Compiler.cs +++ b/src/System.Management.Automation/engine/parser/Compiler.cs @@ -2456,7 +2456,7 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst) { if (!scriptBlockAst.EndBlock.Unnamed) { - funcName = funcName + ""; + funcName += ""; } _endBlockLambda = CompileNamedBlock(scriptBlockAst.EndBlock, funcName, rootForDefiningTypesAndUsings); @@ -5500,7 +5500,7 @@ where t.Label.Equals(labelStrAst.Value, StringComparison.OrdinalIgnoreCase) } else { - labelExpr = labelExpr ?? ExpressionCache.ConstEmptyString; + labelExpr ??= ExpressionCache.ConstEmptyString; result = Expression.Throw(Expression.New(nonLocalExceptionCtor, labelExpr.Convert(typeof(string)))); } @@ -6428,7 +6428,7 @@ public object VisitArrayExpression(ArrayExpressionAst arrayExpressionAst) } } - values = values ?? CaptureAstResults(subExpr, CaptureAstContext.Enumerable); + values ??= CaptureAstResults(subExpr, CaptureAstContext.Enumerable); if (pureExprAst is ArrayLiteralAst) { diff --git a/src/System.Management.Automation/engine/parser/PSType.cs b/src/System.Management.Automation/engine/parser/PSType.cs index 8a18f880bab..dd544907ca1 100644 --- a/src/System.Management.Automation/engine/parser/PSType.cs +++ b/src/System.Management.Automation/engine/parser/PSType.cs @@ -1411,7 +1411,7 @@ private static string GetClassNameInAssembly(TypeDefinitionAst typeDefinitionAst { if (parent is IParameterMetadataProvider) { - nameParts = nameParts ?? new List(); + nameParts ??= new List(); var fnDefn = parent.Parent as FunctionDefinitionAst; if (fnDefn != null) { diff --git a/src/System.Management.Automation/engine/parser/Parser.cs b/src/System.Management.Automation/engine/parser/Parser.cs index e3245e91564..fb57f12466d 100644 --- a/src/System.Management.Automation/engine/parser/Parser.cs +++ b/src/System.Management.Automation/engine/parser/Parser.cs @@ -2550,7 +2550,7 @@ private StatementAst SwitchStatementRule(LabelToken labelToken, Token switchToke { SkipToken(); endErrorStatement = switchParameterToken.Extent; - specifiedFlags = specifiedFlags ?? new Dictionary>(); + specifiedFlags ??= new Dictionary>(); if (IsSpecificParameter(switchParameterToken, "regex")) { @@ -2647,7 +2647,7 @@ private StatementAst SwitchStatementRule(LabelToken labelToken, Token switchToke if (switchParameterToken.Kind == TokenKind.Minus) { - specifiedFlags = specifiedFlags ?? new Dictionary>(); + specifiedFlags ??= new Dictionary>(); specifiedFlags.Add(VERBATIM_ARGUMENT, new Tuple(switchParameterToken, null)); } diff --git a/src/System.Management.Automation/engine/parser/VariableAnalysis.cs b/src/System.Management.Automation/engine/parser/VariableAnalysis.cs index e512ddd3938..092a9fc9a49 100644 --- a/src/System.Management.Automation/engine/parser/VariableAnalysis.cs +++ b/src/System.Management.Automation/engine/parser/VariableAnalysis.cs @@ -626,7 +626,7 @@ private Tuple> AnalyzeImpl(IParameterMetadataProvi var varName = GetUnaliasedVariableName(variablePath); var details = _variables[varName]; details.Assigned = true; - type = type ?? details.Type ?? typeof(object); + type ??= details.Type ?? typeof(object); // automatic and preference variables are pre-allocated, so they can't be unallocated // and forced to be dynamic. diff --git a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs index 71985462fc5..1254c5ca420 100644 --- a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs +++ b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs @@ -708,7 +708,7 @@ private string ConstructTemporaryFile(string pluginContent) try { // Make sure the file is not read only - destfile.Attributes = destfile.Attributes & ~(FileAttributes.ReadOnly | FileAttributes.Hidden); + destfile.Attributes &= ~(FileAttributes.ReadOnly | FileAttributes.Hidden); destfile.Delete(); } catch (FileNotFoundException fnf) diff --git a/src/System.Management.Automation/engine/remoting/common/fragmentor.cs b/src/System.Management.Automation/engine/remoting/common/fragmentor.cs index 832b89a7562..63dc48b96a9 100644 --- a/src/System.Management.Automation/engine/remoting/common/fragmentor.cs +++ b/src/System.Management.Automation/engine/remoting/common/fragmentor.cs @@ -578,7 +578,7 @@ public override void Write(byte[] buffer, int offset, int count) if (dataLeftInTheFragment > 0) { int amountToWriteIntoFragment = (amountLeft > dataLeftInTheFragment) ? dataLeftInTheFragment : amountLeft; - amountLeft = amountLeft - amountToWriteIntoFragment; + amountLeft -= amountToWriteIntoFragment; // Write data into fragment Array.Copy(buffer, offsetToReadFrom, _currentFragment.Blob, _currentFragment.BlobLength, amountToWriteIntoFragment); @@ -799,7 +799,7 @@ private void WriteCurrentFragmentAndReset() } int amountToWriteIntoStream = (amountLeft > dataLeftInWriteStream) ? dataLeftInWriteStream : amountLeft; - amountLeft = amountLeft - amountToWriteIntoStream; + amountLeft -= amountToWriteIntoStream; // write data _writeStream.Position = _writeOffset; _writeStream.Write(data, offSetToReadFrom, amountToWriteIntoStream); diff --git a/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs b/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs index f441a84470c..bac88eff9ef 100644 --- a/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs +++ b/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs @@ -105,7 +105,7 @@ private void InitializeMetadata() { if (attribute is CmdletBindingAttribute c) { - cmdletBindingAttribute = cmdletBindingAttribute ?? c; + cmdletBindingAttribute ??= c; } else if (attribute is DebuggerHiddenAttribute) { @@ -739,7 +739,7 @@ internal SteppablePipeline GetSteppablePipelineImpl(CommandOrigin commandOrigin, private PipelineAst GetSimplePipeline(Func errorHandler) { - errorHandler = errorHandler ?? (_ => null); + errorHandler ??= (_ => null); if (HasBeginBlock || HasProcessBlock) { @@ -2001,7 +2001,7 @@ public static string Match(string text) uint h = text[i]; if (h >= 'A' && h <= 'Z') { - h = h | 0x20; // ToLower + h |= 0x20; // ToLower } else if (!((h >= 'a' && h <= 'z') || h == '-')) { diff --git a/src/System.Management.Automation/engine/runtime/MutableTuple.cs b/src/System.Management.Automation/engine/runtime/MutableTuple.cs index de923e2df8b..4d813166795 100644 --- a/src/System.Management.Automation/engine/runtime/MutableTuple.cs +++ b/src/System.Management.Automation/engine/runtime/MutableTuple.cs @@ -511,7 +511,7 @@ private static int PowerOfTwoRound(int value) int res = 1; while (value > res) { - res = res << 1; + res <<= 1; } return res; diff --git a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs index dc4a8fbe204..699e9bc5cf4 100644 --- a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs +++ b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs @@ -104,7 +104,7 @@ private static CommandProcessorBase AddCommand(PipelineProcessor pipe, else { var commandName = command as string ?? PSObject.ToStringParser(context, command); - invocationName = invocationName ?? commandName; + invocationName ??= commandName; if (string.IsNullOrEmpty(commandName)) { @@ -1419,7 +1419,7 @@ private static int[] RankExceptionTypes(Type[] types) if (types[length - 1].Equals(typeof(CatchAll))) { ranks[length - 1] = length - 1; - length = length - 1; + length -= 1; } // For each type check if it's a sub-class of any types after it. diff --git a/src/System.Management.Automation/engine/serialization.cs b/src/System.Management.Automation/engine/serialization.cs index de5d107404c..f1c4b35bb96 100644 --- a/src/System.Management.Automation/engine/serialization.cs +++ b/src/System.Management.Automation/engine/serialization.cs @@ -346,7 +346,7 @@ internal void LogExtraMemoryUsage(int amountOfExtraMemory) throw new XmlException(message); } - _totalDataProcessedSoFar = _totalDataProcessedSoFar + amountOfExtraMemory; + _totalDataProcessedSoFar += amountOfExtraMemory; } } diff --git a/src/System.Management.Automation/help/HelpProvider.cs b/src/System.Management.Automation/help/HelpProvider.cs index 76ce3168432..0142714f7b8 100644 --- a/src/System.Management.Automation/help/HelpProvider.cs +++ b/src/System.Management.Automation/help/HelpProvider.cs @@ -175,7 +175,7 @@ internal virtual IEnumerable ProcessForwardedHelp(HelpInfo helpInfo, H { // Win8: 508648. Remove the current provides category for resolving forward help as the current // help provider already process it. - helpInfo.ForwardHelpCategory = helpInfo.ForwardHelpCategory ^ this.HelpCategory; + helpInfo.ForwardHelpCategory ^= this.HelpCategory; yield return helpInfo; } diff --git a/src/System.Management.Automation/help/UpdatableHelpSystem.cs b/src/System.Management.Automation/help/UpdatableHelpSystem.cs index 0a45b9a7605..ed1c514f498 100644 --- a/src/System.Management.Automation/help/UpdatableHelpSystem.cs +++ b/src/System.Management.Automation/help/UpdatableHelpSystem.cs @@ -1002,7 +1002,7 @@ private void RemoveReadOnly(string path) if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { - attributes = (attributes & ~FileAttributes.ReadOnly); + attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(path, attributes); } } diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index be4b95dc935..1abf32573c4 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -3267,7 +3267,7 @@ private void RemoveFileSystemItem(FileSystemInfo fileSystemInfo, bool force) // if they've specified force. if (force) { - fileSystemInfo.Attributes = fileSystemInfo.Attributes & ~(FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System); + fileSystemInfo.Attributes &= ~(FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System); attributeRecoveryRequired = true; } @@ -3999,8 +3999,7 @@ private void CopyFileInfoItem(FileInfo file, string destinationPath, bool force, // try again FileInfo destinationItem = new FileInfo(destinationPath); - destinationItem.Attributes = - destinationItem.Attributes & ~(FileAttributes.ReadOnly | FileAttributes.Hidden); + destinationItem.Attributes &= ~(FileAttributes.ReadOnly | FileAttributes.Hidden); } else { @@ -4256,19 +4255,19 @@ private void SetFileMetadata(string sourceFileFullName, FileInfo destinationFile { if (string.Equals(value, "ReadOnly", StringComparison.OrdinalIgnoreCase)) { - destinationFile.Attributes = destinationFile.Attributes | FileAttributes.ReadOnly; + destinationFile.Attributes |= FileAttributes.ReadOnly; } else if (string.Equals(value, "Hidden", StringComparison.OrdinalIgnoreCase)) { - destinationFile.Attributes = destinationFile.Attributes | FileAttributes.Hidden; + destinationFile.Attributes |= FileAttributes.Hidden; } else if (string.Equals(value, "Archive", StringComparison.OrdinalIgnoreCase)) { - destinationFile.Attributes = destinationFile.Attributes | FileAttributes.Archive; + destinationFile.Attributes |= FileAttributes.Archive; } else if (string.Equals(value, "System", StringComparison.OrdinalIgnoreCase)) { - destinationFile.Attributes = destinationFile.Attributes | FileAttributes.System; + destinationFile.Attributes |= FileAttributes.System; } } } @@ -4361,7 +4360,7 @@ private bool PerformCopyFileFromRemoteSession(string sourceFileFullName, FileInf // If force is specified, and the file already exist at the destination, mask of the readonly, hidden, and system attributes if (force && File.Exists(destinationFile.FullName)) { - destinationFile.Attributes = destinationFile.Attributes & ~(FileAttributes.ReadOnly | FileAttributes.Hidden | FileAttributes.System); + destinationFile.Attributes &= ~(FileAttributes.ReadOnly | FileAttributes.Hidden | FileAttributes.System); } wStream = new FileStream(destinationFile.FullName, FileMode.Create); @@ -5410,7 +5409,7 @@ private string NormalizeRelativePathHelper(string path, string basePath) #if !UNIX if (!string.IsNullOrEmpty(alternateDataStream)) { - result = result + alternateDataStream; + result += alternateDataStream; } #endif @@ -5901,8 +5900,7 @@ private void MoveFileInfoItem( try { // mask off the readonly and hidden bits and try again - file.Attributes = - file.Attributes & ~(FileAttributes.ReadOnly | FileAttributes.Hidden); + file.Attributes &= ~(FileAttributes.ReadOnly | FileAttributes.Hidden); file.MoveTo(destination); @@ -5950,7 +5948,7 @@ private void MoveFileInfoItem( try { // Make sure the file is not read only - destfile.Attributes = destfile.Attributes & ~(FileAttributes.ReadOnly | FileAttributes.Hidden); + destfile.Attributes &= ~(FileAttributes.ReadOnly | FileAttributes.Hidden); destfile.Delete(); file.MoveTo(destination); @@ -6022,8 +6020,7 @@ private void MoveDirectoryInfoItem( try { // mask off the readonly and hidden bits and try again - directory.Attributes = - directory.Attributes & ~(FileAttributes.ReadOnly | FileAttributes.Hidden); + directory.Attributes &= ~(FileAttributes.ReadOnly | FileAttributes.Hidden); MoveDirectoryInfoUnchecked(directory, destination, force); diff --git a/src/System.Management.Automation/namespaces/NavigationProviderBase.cs b/src/System.Management.Automation/namespaces/NavigationProviderBase.cs index 6732f6e7af8..54750dcd1bf 100644 --- a/src/System.Management.Automation/namespaces/NavigationProviderBase.cs +++ b/src/System.Management.Automation/namespaces/NavigationProviderBase.cs @@ -650,7 +650,7 @@ internal string ContractRelativePath( if (originalPathHadTrailingSlash) { - result = result + StringLiterals.DefaultPathSeparator; + result += StringLiterals.DefaultPathSeparator; } return result; diff --git a/src/System.Management.Automation/security/CatalogHelper.cs b/src/System.Management.Automation/security/CatalogHelper.cs index 787f0c234a0..f984976b33d 100644 --- a/src/System.Management.Automation/security/CatalogHelper.cs +++ b/src/System.Management.Automation/security/CatalogHelper.cs @@ -337,7 +337,7 @@ internal static FileInfo GenerateCatalog(PSCmdlet cmdlet, Collection Pat { // Generate Path for Catalog Definition File string cdfFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName()); - cdfFilePath = cdfFilePath + ".cdf"; + cdfFilePath += ".cdf"; try { cdfFilePath = GenerateCDFFile(Path, catalogFilePath, cdfFilePath, catalogVersion, hashAlgorithm); diff --git a/src/System.Management.Automation/utils/ClrFacade.cs b/src/System.Management.Automation/utils/ClrFacade.cs index 3b9a514be5e..0372b249ca1 100644 --- a/src/System.Management.Automation/utils/ClrFacade.cs +++ b/src/System.Management.Automation/utils/ClrFacade.cs @@ -349,12 +349,12 @@ internal static string ToDmtfDateTime(DateTime date) string dmtfDateTime = date.Year.ToString(frmInt32).PadLeft(4, '0'); - dmtfDateTime = (dmtfDateTime + date.Month.ToString(frmInt32).PadLeft(2, '0')); - dmtfDateTime = (dmtfDateTime + date.Day.ToString(frmInt32).PadLeft(2, '0')); - dmtfDateTime = (dmtfDateTime + date.Hour.ToString(frmInt32).PadLeft(2, '0')); - dmtfDateTime = (dmtfDateTime + date.Minute.ToString(frmInt32).PadLeft(2, '0')); - dmtfDateTime = (dmtfDateTime + date.Second.ToString(frmInt32).PadLeft(2, '0')); - dmtfDateTime = (dmtfDateTime + "."); + dmtfDateTime += date.Month.ToString(frmInt32).PadLeft(2, '0'); + dmtfDateTime += date.Day.ToString(frmInt32).PadLeft(2, '0'); + dmtfDateTime += date.Hour.ToString(frmInt32).PadLeft(2, '0'); + dmtfDateTime += date.Minute.ToString(frmInt32).PadLeft(2, '0'); + dmtfDateTime += date.Second.ToString(frmInt32).PadLeft(2, '0'); + dmtfDateTime += "."; // Construct a DateTime with with the precision to Second as same as the passed DateTime and so get // the ticks difference so that the microseconds can be calculated @@ -368,9 +368,9 @@ internal static string ToDmtfDateTime(DateTime date) strMicrosec = strMicrosec.Substring(0, 6); } - dmtfDateTime = dmtfDateTime + strMicrosec.PadLeft(6, '0'); + dmtfDateTime += strMicrosec.PadLeft(6, '0'); // adding the UTC offset - dmtfDateTime = dmtfDateTime + UtcString; + dmtfDateTime += UtcString; return dmtfDateTime; #else diff --git a/src/System.Management.Automation/utils/ExtensionMethods.cs b/src/System.Management.Automation/utils/ExtensionMethods.cs index 223aa793af5..f3dc94c047b 100644 --- a/src/System.Management.Automation/utils/ExtensionMethods.cs +++ b/src/System.Management.Automation/utils/ExtensionMethods.cs @@ -43,10 +43,10 @@ internal static int SequenceGetHashCode(this IEnumerable xs) int hash = 41; // 41 is a random prime number foreach (T x in xs) { - hash = hash * 59; // 59 is a random prime number + hash *= 59; // 59 is a random prime number if (x != null) { - hash = hash + x.GetHashCode(); + hash += x.GetHashCode(); } }