Enable IDE0054: Use compound assignment (#13546)

* Autofix IDE0054
https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0054-ide0074
This commit is contained in:
xtqqczze
2020-11-05 09:48:13 +05:00
committed by GitHub
parent 03a0ef26e6
commit 3ba61069b8
43 changed files with 123 additions and 126 deletions
+1 -1
View File
@@ -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
@@ -2505,7 +2505,7 @@ namespace Microsoft.PowerShell.Commands
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);
}
@@ -102,7 +102,7 @@ namespace Microsoft.PowerShell.Commands
if (verboseString.Length >= 20)
{
verboseString = verboseString.Substring(0, 20);
verboseString = verboseString + " ...";
verboseString += " ...";
}
}
@@ -388,7 +388,7 @@ namespace Microsoft.PowerShell.Commands
memberCount++;
}
memberCountHelper = memberCountHelper >> 1;
memberCountHelper >>= 1;
}
if (memberCount != 1)
@@ -334,7 +334,7 @@ namespace Microsoft.PowerShell.Commands
{
double r = Generator.NextDouble();
randomNumber = minValue + r * diff;
diff = diff * r;
diff *= r;
}
while (randomNumber >= maxValue);
}
@@ -2430,7 +2430,7 @@ function Get-PSImplicitRemotingSession
out hashString,
ImplicitRemotingCommandBase.ImplicitRemotingKey,
ImplicitRemotingCommandBase.ImplicitRemotingHashKey);
hashString = hashString ?? string.Empty;
hashString ??= string.Empty;
writer.Write(
HelperFunctionsGetImplicitRunspaceTemplate,
@@ -2670,19 +2670,19 @@ namespace Microsoft.PowerShell.Commands
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<WildcardPattern>();
foreach (var pattern in dp.Eku)
{
@@ -2692,13 +2692,13 @@ namespace Microsoft.PowerShell.Commands
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;
}
}
@@ -577,7 +577,7 @@ namespace Microsoft.PowerShell.Commands
if (postContext != null)
{
resultString = resultString + postContext;
resultString += postContext;
}
}
@@ -439,7 +439,7 @@ namespace Microsoft.WSMan.Management
// 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 @@ namespace Microsoft.WSMan.Management
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 @@ namespace Microsoft.WSMan.Management
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 @@ namespace Microsoft.WSMan.Management
// 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 @@ namespace Microsoft.WSMan.Management
// 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 @@ namespace Microsoft.WSMan.Management
return true;
}
strPathCheck = strPathCheck + WSManStringLiterals.DefaultPathSeparator;
strPathCheck += WSManStringLiterals.DefaultPathSeparator;
if (path.EndsWith(strPathCheck + WSManStringLiterals.containerResources, StringComparison.OrdinalIgnoreCase))
{
return true;
@@ -1695,7 +1695,7 @@ namespace Microsoft.WSMan.Management
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 @@ namespace Microsoft.WSMan.Management
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 @@ namespace Microsoft.WSMan.Management
while (!((IWSManEnumerator)value).AtEndOfStream)
{
strXmlValue = strXmlValue + ((IWSManEnumerator)value).ReadItem();
strXmlValue += ((IWSManEnumerator)value).ReadItem();
}
Marshal.ReleaseComObject(value);
@@ -2900,7 +2900,7 @@ namespace Microsoft.WSMan.Management
while (!((IWSManEnumerator)value).AtEndOfStream)
{
valuexml = valuexml + ((IWSManEnumerator)value).ReadItem();
valuexml += ((IWSManEnumerator)value).ReadItem();
}
if ((valuexml != string.Empty) && !(string.IsNullOrEmpty(valuexml)))
@@ -413,7 +413,7 @@ namespace Microsoft.WSMan.Management
filter = filter + "<wsman:Selector Name='" + name + "'>" + value + "</wsman:Selector>";
}
filter = filter + "</wsman:SelectorSet>";
filter += "</wsman:SelectorSet>";
return (filter);
}
+16 -16
View File
@@ -562,7 +562,7 @@ namespace Microsoft.WSMan.Management
if (selectorset != null)
{
resource = resource + "?";
resource += "?";
int i = 0;
foreach (DictionaryEntry entry in selectorset)
{
@@ -656,7 +656,7 @@ namespace Microsoft.WSMan.Management
{
if (authentication.Equals(AuthenticationMechanism.None))
{
sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseNoAuthentication;
sessionFlags |= (int)WSManSessionFlags.WSManFlagUseNoAuthentication;
}
if (authentication.Equals(AuthenticationMechanism.Basic))
@@ -666,12 +666,12 @@ namespace Microsoft.WSMan.Management
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 @@ namespace Microsoft.WSMan.Management
if (authentication.Equals(AuthenticationMechanism.ClientCertificate))
{
sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseClientCertificate;
sessionFlags |= (int)WSManSessionFlags.WSManFlagUseClientCertificate;
}
}
@@ -718,7 +718,7 @@ namespace Microsoft.WSMan.Management
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 @@ namespace Microsoft.WSMan.Management
if (certificateThumbprint != null)
{
connObject.CertificateThumbprint = certificateThumbprint;
sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseClientCertificate;
sessionFlags |= (int)WSManSessionFlags.WSManFlagUseClientCertificate;
}
if (sessionoption != null)
@@ -784,48 +784,48 @@ namespace Microsoft.WSMan.Management
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;
@@ -4119,7 +4119,7 @@ namespace System.Management.Automation
/*argumentAst*/null, parameterValue,
false);
flags = flags & ~ParameterBindingFlags.DelayBindScriptBlock;
flags &= ~ParameterBindingFlags.DelayBindScriptBlock;
result = BindParameter(_currentParameterSetFlag, param, parameter, flags);
if (result)
@@ -891,7 +891,7 @@ namespace System.Management.Automation
// 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);
@@ -1443,7 +1443,7 @@ namespace System.Management.Automation
{
string completionText = isCursorInString ? value : stringQuote + value + stringQuote;
if (hasNewLine)
completionText = completionText + stringQuote;
completionText += stringQuote;
result.Add(new CompletionResult(
completionText,
value,
@@ -1494,7 +1494,7 @@ namespace System.Management.Automation
{
string completionText = isCursorInString ? resource : stringQuote + resource + stringQuote;
if (hasNewLine)
completionText = completionText + stringQuote;
completionText += stringQuote;
result.Add(new CompletionResult(
completionText,
resource,
@@ -3630,7 +3630,7 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
// 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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
if (leaf != null)
{
leaf = leaf + "*";
leaf += "*";
var parentPath = Path.GetDirectoryName(providerPath);
// ProviderPath should be absolute path for FileSystem entries
@@ -1151,12 +1151,12 @@ namespace System.Management.Automation.Language
_bindableParameters = null;
// reuse the collections/dictionaries
_arguments = _arguments ?? new Collection<AstParameterArgumentPair>();
_boundParameters = _boundParameters ?? new Dictionary<string, MergedCompiledCommandParameter>(StringComparer.OrdinalIgnoreCase);
_boundArguments = _boundArguments ?? new Dictionary<string, AstParameterArgumentPair>(StringComparer.OrdinalIgnoreCase);
_unboundParameters = _unboundParameters ?? new List<MergedCompiledCommandParameter>();
_boundPositionalParameter = _boundPositionalParameter ?? new Collection<string>();
_bindingExceptions = _bindingExceptions ?? new Dictionary<CommandParameterAst, ParameterBindingException>();
_arguments ??= new Collection<AstParameterArgumentPair>();
_boundParameters ??= new Dictionary<string, MergedCompiledCommandParameter>(StringComparer.OrdinalIgnoreCase);
_boundArguments ??= new Dictionary<string, AstParameterArgumentPair>(StringComparer.OrdinalIgnoreCase);
_unboundParameters ??= new List<MergedCompiledCommandParameter>();
_boundPositionalParameter ??= new Collection<string>();
_bindingExceptions ??= new Dictionary<CommandParameterAst, ParameterBindingException>();
_arguments.Clear();
_boundParameters.Clear();
@@ -1171,9 +1171,9 @@ namespace System.Management.Automation.Language
_isPipelineInputExpected = false;
// reuse the collections
_parametersNotFound = _parametersNotFound ?? new Collection<CommandParameterAst>();
_ambiguousParameters = _ambiguousParameters ?? new Collection<CommandParameterAst>();
_duplicateParameters = _duplicateParameters ?? new Collection<AstParameterArgumentPair>();
_parametersNotFound ??= new Collection<CommandParameterAst>();
_ambiguousParameters ??= new Collection<CommandParameterAst>();
_duplicateParameters ??= new Collection<AstParameterArgumentPair>();
_parametersNotFound.Clear();
_ambiguousParameters.Clear();
@@ -652,7 +652,7 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
return null;
}
sessionState = sessionState ?? scriptCommandInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState;
sessionState ??= scriptCommandInfo.ScriptBlock.SessionStateInternal ?? context.EngineSessionState;
return new CommandProcessor(scriptCommandInfo, context, useNewScope, fromScriptFile, sessionState);
}
@@ -5244,12 +5244,12 @@ end {
cmdlet.SetModule(moduleInfo);
}
cmdlets = cmdlets ?? new Dictionary<string, SessionStateCmdletEntry>(StringComparer.OrdinalIgnoreCase);
cmdlets ??= new Dictionary<string, SessionStateCmdletEntry>(StringComparer.OrdinalIgnoreCase);
cmdlets.Add(cmdletName, cmdlet);
if (TryGetCustomAttribute(type, out AliasAttribute aliasAttribute))
{
aliases = aliases ?? new Dictionary<string, List<SessionStateAliasEntry>>(StringComparer.OrdinalIgnoreCase);
aliases ??= new Dictionary<string, List<SessionStateAliasEntry>>(StringComparer.OrdinalIgnoreCase);
var aliasList = new List<SessionStateAliasEntry>();
foreach (var alias in aliasAttribute.AliasNames)
@@ -5302,7 +5302,7 @@ end {
provider.SetModule(moduleInfo);
}
providers = providers ?? new Dictionary<string, SessionStateProviderEntry>(StringComparer.OrdinalIgnoreCase);
providers ??= new Dictionary<string, SessionStateProviderEntry>(StringComparer.OrdinalIgnoreCase);
providers.Add(providerName, provider);
s_PSSnapInTracer.WriteLine("{0} from type {1} is added as a provider. ", providerName, type.FullName);
@@ -271,7 +271,7 @@ namespace System.Management.Automation
}
else
{
seen = seen | parameter;
seen |= parameter;
}
}
@@ -1144,7 +1144,7 @@ namespace Microsoft.PowerShell.Commands
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++)
{
@@ -744,7 +744,7 @@ namespace System.Management.Automation
Cmdlet cmdlet,
CancellationToken cancellationToken)
{
moduleNamePatterns = moduleNamePatterns ?? new[] { "*" };
moduleNamePatterns ??= new[] { "*" };
HashSet<string> alreadyEmittedNamesOfCimModules = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
IEnumerable<CimModule> remoteModules = moduleNamePatterns
@@ -855,9 +855,9 @@ namespace System.Management.Automation
IEnumerable<string> typesToProcess,
IEnumerable<string> formatsToProcess)
{
nestedModules = nestedModules ?? Array.Empty<string>();
typesToProcess = typesToProcess ?? Array.Empty<string>();
formatsToProcess = formatsToProcess ?? Array.Empty<string>();
nestedModules ??= Array.Empty<string>();
typesToProcess ??= Array.Empty<string>();
formatsToProcess ??= Array.Empty<string>();
var newManifest = new Hashtable(StringComparer.OrdinalIgnoreCase);
newManifest["NestedModules"] = nestedModules;
@@ -1037,7 +1037,7 @@ namespace System.Management.Automation
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);
@@ -459,7 +459,7 @@ namespace System.Management.Automation
throw bindingException;
}
flags = flags & ~ParameterBindingFlags.DelayBindScriptBlock;
flags &= ~ParameterBindingFlags.DelayBindScriptBlock;
result = BindParameter(_currentParameterSetFlag, argument, matchingParameter, flags);
}
@@ -1179,7 +1179,7 @@ namespace System.Management.Automation
if (variablePath.IsPrivate && varResult != null)
{
varResult.Options = varResult.Options | ScopedItemOptions.Private;
varResult.Options |= ScopedItemOptions.Private;
}
result = varResult;
@@ -265,13 +265,13 @@ namespace System.Management.Automation
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;
}
@@ -101,7 +101,7 @@ namespace System.Management.Automation.Runspaces
name = internalParameter.ParameterText;
if (internalParameter.SpaceAfterParameter)
{
name = name + " ";
name += " ";
}
Diagnostics.Assert(name != null, "'name' variable should be initialized at this point");
@@ -221,7 +221,7 @@ namespace System.Management.Automation.Interpreter
return null;
}
// return the last one that is smaller
i = i - 1;
i -= 1;
}
return debugInfos[i];
@@ -2456,7 +2456,7 @@ namespace System.Management.Automation.Language
{
if (!scriptBlockAst.EndBlock.Unnamed)
{
funcName = funcName + "<End>";
funcName += "<End>";
}
_endBlockLambda = CompileNamedBlock(scriptBlockAst.EndBlock, funcName, rootForDefiningTypesAndUsings);
@@ -5500,7 +5500,7 @@ namespace System.Management.Automation.Language
}
else
{
labelExpr = labelExpr ?? ExpressionCache.ConstEmptyString;
labelExpr ??= ExpressionCache.ConstEmptyString;
result = Expression.Throw(Expression.New(nonLocalExceptionCtor, labelExpr.Convert(typeof(string))));
}
@@ -6428,7 +6428,7 @@ namespace System.Management.Automation.Language
}
}
values = values ?? CaptureAstResults(subExpr, CaptureAstContext.Enumerable);
values ??= CaptureAstResults(subExpr, CaptureAstContext.Enumerable);
if (pureExprAst is ArrayLiteralAst)
{
@@ -1411,7 +1411,7 @@ namespace System.Management.Automation.Language
{
if (parent is IParameterMetadataProvider)
{
nameParts = nameParts ?? new List<string>();
nameParts ??= new List<string>();
var fnDefn = parent.Parent as FunctionDefinitionAst;
if (fnDefn != null)
{
@@ -2550,7 +2550,7 @@ namespace System.Management.Automation.Language
{
SkipToken();
endErrorStatement = switchParameterToken.Extent;
specifiedFlags = specifiedFlags ?? new Dictionary<string, Tuple<Token, Ast>>();
specifiedFlags ??= new Dictionary<string, Tuple<Token, Ast>>();
if (IsSpecificParameter(switchParameterToken, "regex"))
{
@@ -2647,7 +2647,7 @@ namespace System.Management.Automation.Language
if (switchParameterToken.Kind == TokenKind.Minus)
{
specifiedFlags = specifiedFlags ?? new Dictionary<string, Tuple<Token, Ast>>();
specifiedFlags ??= new Dictionary<string, Tuple<Token, Ast>>();
specifiedFlags.Add(VERBATIM_ARGUMENT, new Tuple<Token, Ast>(switchParameterToken, null));
}
@@ -626,7 +626,7 @@ namespace System.Management.Automation.Language
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.
@@ -708,7 +708,7 @@ else
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)
@@ -578,7 +578,7 @@ namespace System.Management.Automation.Remoting
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 @@ namespace System.Management.Automation.Remoting
}
int amountToWriteIntoStream = (amountLeft > dataLeftInWriteStream) ? dataLeftInWriteStream : amountLeft;
amountLeft = amountLeft - amountToWriteIntoStream;
amountLeft -= amountToWriteIntoStream;
// write data
_writeStream.Position = _writeOffset;
_writeStream.Write(data, offSetToReadFrom, amountToWriteIntoStream);
@@ -105,7 +105,7 @@ namespace System.Management.Automation
{
if (attribute is CmdletBindingAttribute c)
{
cmdletBindingAttribute = cmdletBindingAttribute ?? c;
cmdletBindingAttribute ??= c;
}
else if (attribute is DebuggerHiddenAttribute)
{
@@ -739,7 +739,7 @@ namespace System.Management.Automation
private PipelineAst GetSimplePipeline(Func<string, PipelineAst> errorHandler)
{
errorHandler = errorHandler ?? (_ => null);
errorHandler ??= (_ => null);
if (HasBeginBlock || HasProcessBlock)
{
@@ -2001,7 +2001,7 @@ namespace System.Management.Automation
uint h = text[i];
if (h >= 'A' && h <= 'Z')
{
h = h | 0x20; // ToLower
h |= 0x20; // ToLower
}
else if (!((h >= 'a' && h <= 'z') || h == '-'))
{
@@ -511,7 +511,7 @@ namespace System.Management.Automation
int res = 1;
while (value > res)
{
res = res << 1;
res <<= 1;
}
return res;
@@ -104,7 +104,7 @@ namespace System.Management.Automation
else
{
var commandName = command as string ?? PSObject.ToStringParser(context, command);
invocationName = invocationName ?? commandName;
invocationName ??= commandName;
if (string.IsNullOrEmpty(commandName))
{
@@ -1419,7 +1419,7 @@ namespace System.Management.Automation
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.
@@ -346,7 +346,7 @@ namespace System.Management.Automation
throw new XmlException(message);
}
_totalDataProcessedSoFar = _totalDataProcessedSoFar + amountOfExtraMemory;
_totalDataProcessedSoFar += amountOfExtraMemory;
}
}
@@ -175,7 +175,7 @@ namespace System.Management.Automation
{
// 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;
}
@@ -1002,7 +1002,7 @@ namespace System.Management.Automation.Help
if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
attributes = (attributes & ~FileAttributes.ReadOnly);
attributes &= ~FileAttributes.ReadOnly;
File.SetAttributes(path, attributes);
}
}
@@ -3267,7 +3267,7 @@ namespace Microsoft.PowerShell.Commands
// 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 @@ namespace Microsoft.PowerShell.Commands
// 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 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
// 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 @@ namespace Microsoft.PowerShell.Commands
#if !UNIX
if (!string.IsNullOrEmpty(alternateDataStream))
{
result = result + alternateDataStream;
result += alternateDataStream;
}
#endif
@@ -5901,8 +5900,7 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
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);
@@ -650,7 +650,7 @@ namespace System.Management.Automation.Provider
if (originalPathHadTrailingSlash)
{
result = result + StringLiterals.DefaultPathSeparator;
result += StringLiterals.DefaultPathSeparator;
}
return result;
@@ -337,7 +337,7 @@ namespace System.Management.Automation
{
// 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);
@@ -349,12 +349,12 @@ namespace System.Management.Automation
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 @@ namespace System.Management.Automation
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
@@ -43,10 +43,10 @@ namespace System.Management.Automation
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();
}
}