Use interpolated strings 1 (#18977)

This commit is contained in:
CarloToso
2023-01-21 21:32:26 +05:00
committed by GitHub
parent c156c9cadb
commit 1b3b359bcb
16 changed files with 33 additions and 37 deletions
@@ -951,7 +951,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
CimTestCimSessionContext testCimSessionContext = context as CimTestCimSessionContext;
uint sessionId = this.sessionState.GenerateSessionId();
string originalSessionName = testCimSessionContext.CimSessionWrapper.Name;
string sessionName = originalSessionName ?? string.Format(CultureInfo.CurrentUICulture, @"{0}{1}", CimSessionState.CimSessionClassName, sessionId);
string sessionName = originalSessionName ?? string.Create(CultureInfo.CurrentUICulture, $"{CimSessionState.CimSessionClassName}{sessionId}");
// detach CimSession from the proxy object
CimSession createdCimSession = testCimSessionContext.Proxy.Detach();
@@ -875,7 +875,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
parameters.Append(',');
}
parameters.Append(string.Format(CultureInfo.CurrentUICulture, @"'{0}' = {1}", key, parameterList[key]));
parameters.Append(CultureInfo.CurrentUICulture, $@"'{key}' = {parameterList[key]}");
}
}
@@ -1232,7 +1232,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
this.operationParameters.Add(@"className", className);
this.WriteOperationStartMessage(this.operationName, this.operationParameters);
CimAsyncMultipleResults<CimInstance> asyncResult = this.CimSession.EnumerateInstancesAsync(namespaceName, className, this.OperationOptions);
string errorSource = string.Format(CultureInfo.CurrentUICulture, "{0}:{1}", namespaceName, className);
string errorSource = string.Create(CultureInfo.CurrentUICulture, $"{namespaceName}:{className}");
ConsumeCimInstanceAsync(asyncResult, new CimResultContext(errorSource));
}
@@ -1314,7 +1314,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
this.operationParameters.Add(@"className", className);
this.WriteOperationStartMessage(this.operationName, this.operationParameters);
CimAsyncMultipleResults<CimClass> asyncResult = this.CimSession.EnumerateClassesAsync(namespaceName, className, this.OperationOptions);
string errorSource = string.Format(CultureInfo.CurrentUICulture, "{0}:{1}", namespaceName, className);
string errorSource = string.Create(CultureInfo.CurrentUICulture, $"{namespaceName}:{className}");
ConsumeCimClassAsync(asyncResult, new CimResultContext(errorSource));
}
@@ -1334,7 +1334,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
this.operationParameters.Add(@"className", className);
this.WriteOperationStartMessage(this.operationName, this.operationParameters);
CimAsyncResult<CimClass> asyncResult = this.CimSession.GetClassAsync(namespaceName, className, this.OperationOptions);
string errorSource = string.Format(CultureInfo.CurrentUICulture, "{0}:{1}", namespaceName, className);
string errorSource = string.Create(CultureInfo.CurrentUICulture, $"{namespaceName}:{className}");
ConsumeCimClassAsync(asyncResult, new CimResultContext(errorSource));
}
@@ -1388,7 +1388,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
this.operationParameters.Add(@"methodName", methodName);
this.WriteOperationStartMessage(this.operationName, this.operationParameters);
CimAsyncMultipleResults<CimMethodResultBase> asyncResult = this.CimSession.InvokeMethodAsync(namespaceName, className, methodName, methodParameters, this.OperationOptions);
string errorSource = string.Format(CultureInfo.CurrentUICulture, "{0}:{1}", namespaceName, className);
string errorSource = string.Create(CultureInfo.CurrentUICulture, $"{namespaceName}:{className}");
ConsumeCimInvokeMethodResultAsync(asyncResult, className, methodName, new CimResultContext(errorSource));
}
@@ -205,7 +205,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
case CimBaseCommand.ClassNameComputerSet:
// validate the classname
this.CheckArgument();
tempQueryExpression = string.Format(CultureInfo.CurrentCulture, "Select * from {0}", this.ClassName);
tempQueryExpression = string.Create(CultureInfo.CurrentCulture, $"Select * from {this.ClassName}");
break;
}
@@ -201,16 +201,14 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
StackFrame frame = trace.GetFrame(depth);
// if (withFileName)
// {
// return string.Format(CultureInfo.CurrentUICulture, "{0}#{1}:{2}:", frame.GetFileName()., frame.GetFileLineNumber(), frame.GetMethod().Name);
// return string.Create(CultureInfo.CurrentUICulture, $"{frame.GetFileName().}#{frame.GetFileLineNumber()}:{frame.GetMethod().Name}:");
// }
// else
// {
// return string.Format(CultureInfo.CurrentUICulture, "{0}:", frame.GetMethod());
// return string.Create(CultureInfo.CurrentUICulture, $"{frame.GetMethod()}:");
// }
return string.Format(CultureInfo.CurrentUICulture, "{0}::{1} ",
frame.GetMethod().DeclaringType.Name,
frame.GetMethod().Name);
return string.Create(CultureInfo.CurrentUICulture, $"{frame.GetMethod().DeclaringType.Name}::{frame.GetMethod().Name} ");
}
#endregion
@@ -276,7 +276,7 @@ namespace Microsoft.Management.UI.Internal
foreach (string line in lines)
{
// Indentation is not localized
returnValue.AppendFormat("{0}{1}\r\n", indentString, line);
returnValue.Append($"{indentString}{line}\r\n");
}
if (returnValue.Length > 2)
@@ -369,7 +369,7 @@ namespace Microsoft.Management.UI.Internal
continue;
}
string commandStart = string.Format(CultureInfo.CurrentCulture, "{0} ", commandName);
string commandStart = string.Create(CultureInfo.CurrentCulture, $"{commandName} ");
this.AddText(HelpParagraphBuilder.AddIndent(commandStart), false);
foreach (object parameterObj in parameterObjs)
@@ -389,7 +389,7 @@ namespace Microsoft.Management.UI.Internal
continue;
}
string parameterType = parameterValue == null ? string.Empty : string.Format(CultureInfo.CurrentCulture, "<{0}>", parameterValue);
string parameterType = parameterValue == null ? string.Empty : string.Create(CultureInfo.CurrentCulture, $"<{parameterValue}>");
string parameterOptionalOpenBrace, parameterOptionalCloseBrace;
@@ -607,7 +607,7 @@ namespace Microsoft.Management.UI.Internal
description = GetPropertyString(propertyTypeObject, "description");
}
memberText = string.Format(CultureInfo.CurrentCulture, " [{0}] {1}\r\n", propertyType, name);
memberText = string.Create(CultureInfo.CurrentCulture, $" [{propertyType}] {name}\r\n");
}
}
else if (string.Equals("method", type, StringComparison.OrdinalIgnoreCase))
@@ -697,7 +697,7 @@ namespace Microsoft.Management.UI.Internal
}
}
string paramString = string.Format(CultureInfo.CurrentCulture, "[{0}] ${1},", parameterType, parameterName);
string paramString = string.Create(CultureInfo.CurrentCulture, $"[{parameterType}] ${parameterName},");
parameterText.Append(paramString);
}
@@ -709,7 +709,7 @@ namespace Microsoft.Management.UI.Internal
}
}
memberText = string.Format(CultureInfo.CurrentCulture, " [{0}] {1}({2})\r\n", returnType, name, parameterText);
memberText = string.Create(CultureInfo.CurrentCulture, $" [{returnType}] {name}({parameterText})\r\n");
}
/// <summary>
@@ -188,7 +188,7 @@ namespace Microsoft.Management.UI.Internal
{
if (!columnName.Equals(SelectedIndexPropertyName, StringComparison.CurrentCulture))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "{0} is not a valid column name.", columnName), "columnName");
throw new ArgumentException(string.Create(CultureInfo.CurrentCulture, $"{columnName} is not a valid column name."), "columnName");
}
if (!this.IsIndexWithinBounds(this.SelectedIndex))
@@ -218,7 +218,7 @@ namespace Microsoft.Management.UI.Internal
DataErrorInfoValidationResult result = rule.Validate(value, cultureInfo);
if (result == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "DataErrorInfoValidationResult not returned by ValidationRule: {0}", rule.ToString()));
throw new InvalidOperationException(string.Create(CultureInfo.CurrentCulture, $"DataErrorInfoValidationResult not returned by ValidationRule: {rule}"));
}
if (!result.IsValid)
@@ -121,7 +121,7 @@ namespace Microsoft.Management.UI.Internal
patterns.Add(rule.Pattern);
}
patterns.Add(string.Format(CultureInfo.InvariantCulture, "(?<{0}>){1}", FullTextRuleGroupName, ValuePattern));
patterns.Add(string.Create(CultureInfo.InvariantCulture, $"(?<{FullTextRuleGroupName}>){ValuePattern}"));
return string.Join("|", patterns.ToArray());
}
@@ -199,7 +199,7 @@ namespace Microsoft.Management.UI.Internal
this.UniqueId = uniqueId;
this.selectorFilterRule = selectorFilterRule;
this.childRule = childRule;
this.Pattern = string.Format(CultureInfo.InvariantCulture, "(?<{0}>){1}\\s*:\\s*{2}", uniqueId, Regex.Escape(selectorFilterRule.DisplayName), SearchTextParser.ValuePattern);
this.Pattern = string.Create(CultureInfo.InvariantCulture, $"(?<{uniqueId}>){Regex.Escape(selectorFilterRule.DisplayName)}\\s*:\\s*{SearchTextParser.ValuePattern}");
}
/// <summary>
@@ -596,7 +596,7 @@ namespace Microsoft.Management.UI.Internal
propertyValue = string.Empty;
}
entryText.AppendFormat(CultureInfo.CurrentCulture, "{0}\t", propertyValue);
entryText.Append(CultureInfo.CurrentCulture, $"{propertyValue}\t");
}
return entryText.ToString();
@@ -35,7 +35,7 @@ namespace Microsoft.Management.UI.Internal
}
string name = (!string.IsNullOrEmpty(cvg.Name.ToString())) ? cvg.Name.ToString() : UICultureResources.GroupTitleNone;
string display = string.Format(CultureInfo.CurrentCulture, "{0} ({1})", name, cvg.ItemCount);
string display = string.Create(CultureInfo.CurrentCulture, $"{name} ({cvg.ItemCount})");
return display;
}
@@ -43,7 +43,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
foreach (object selectedItem in multipleSelectionDialog.listboxParameter.SelectedItems)
{
newComboText.AppendFormat(CultureInfo.InvariantCulture, "{0},", selectedItem.ToString());
newComboText.Append(CultureInfo.InvariantCulture, $"{selectedItem},");
}
if (newComboText.Length > 1)
@@ -94,7 +94,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
//// Add AutomationProperties.AutomationId for Ui Automation test.
checkBox.SetValue(
System.Windows.Automation.AutomationProperties.AutomationIdProperty,
string.Format(CultureInfo.CurrentCulture, "chk{0}", parameterViewModel.Name));
string.Create(CultureInfo.CurrentCulture, $"chk{parameterViewModel.Name}"));
checkBox.SetValue(
System.Windows.Automation.AutomationProperties.NameProperty,
@@ -124,10 +124,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
Binding selectedItemBinding = new Binding("Value");
comboBox.SetBinding(ComboBox.SelectedItemProperty, selectedItemBinding);
string automationId = string.Format(
CultureInfo.CurrentCulture,
"combox{0}",
parameterViewModel.Name);
string automationId = string.Create(CultureInfo.CurrentCulture, $"combox{parameterViewModel.Name}");
//// Add AutomationProperties.AutomationId for Ui Automation test.
comboBox.SetValue(
@@ -164,7 +161,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
multiControls.comboxParameter.SetBinding(ComboBox.TextProperty, valueBinding);
// Add AutomationProperties.AutomationId for Ui Automation test.
multiControls.SetValue(System.Windows.Automation.AutomationProperties.AutomationIdProperty, string.Format("combox{0}", parameterViewModel.Name));
multiControls.SetValue(System.Windows.Automation.AutomationProperties.AutomationIdProperty, string.Create(CultureInfo.CurrentCulture, $"combox{parameterViewModel.Name}"));
multiControls.comboxParameter.SetValue(
System.Windows.Automation.AutomationProperties.NameProperty,
@@ -206,7 +203,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
//// Add AutomationProperties.AutomationId for UI Automation test.
textBox.SetValue(
System.Windows.Automation.AutomationProperties.AutomationIdProperty,
string.Format(CultureInfo.CurrentCulture, "txt{0}", parameterViewModel.Name));
string.Create(CultureInfo.CurrentCulture, $"txt{parameterViewModel.Name}"));
textBox.SetValue(
System.Windows.Automation.AutomationProperties.NameProperty,
@@ -397,7 +394,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
//// Add AutomationProperties.AutomationId for Ui Automation test.
label.SetValue(
System.Windows.Automation.AutomationProperties.AutomationIdProperty,
string.Format(CultureInfo.CurrentCulture, "lbl{0}", parameterViewModel.Name));
string.Create(CultureInfo.CurrentCulture, $"lbl{parameterViewModel.Name}"));
return label;
}
@@ -431,7 +431,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
if (commandName.Contains(' '))
{
builder.AppendFormat("& \"{0}\"", commandName);
builder.Append($"& \"{commandName}\"");
}
else
{
@@ -138,7 +138,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
{
if (((bool?)parameter.Value) == true)
{
builder.AppendFormat("-{0} ", parameter.Name);
builder.Append($"-{parameter.Name} ");
}
continue;
@@ -166,7 +166,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
parameterValueString = ParameterSetViewModel.GetDelimitedParameter(parameterValueString, "(", ")");
}
builder.AppendFormat("-{0} {1} ", parameter.Name, parameterValueString);
builder.Append($"-{parameter.Name} {parameterValueString} ");
}
return builder.ToString().Trim();
@@ -159,7 +159,7 @@ namespace Microsoft.PowerShell.Commands.ShowCommandInternal
string returnValue = this.Parameter.Name;
if (this.Parameter.IsMandatory)
{
returnValue = string.Format(CultureInfo.CurrentUICulture, "{0}{1}", returnValue, ShowCommandResources.MandatoryLabelSegment);
returnValue = string.Create(CultureInfo.CurrentUICulture, $"{returnValue}{ShowCommandResources.MandatoryLabelSegment}");
}
return returnValue;
@@ -9,6 +9,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>10.0</LangVersion>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<ItemGroup>