Skip to content

Commit b195088

Browse files
authored
Revert some of the interpolated string changes (PowerShell#19018)
1 parent 1c27a0c commit b195088

File tree

35 files changed

+300
-103
lines changed

35 files changed

+300
-103
lines changed

src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,6 @@ internal static string GetSourceCodeInformation(bool withFileName, int depth)
199199
{
200200
StackTrace trace = new();
201201
StackFrame frame = trace.GetFrame(depth);
202-
// if (withFileName)
203-
// {
204-
// return string.Create(CultureInfo.CurrentUICulture, $"{frame.GetFileName().}#{frame.GetFileLineNumber()}:{frame.GetMethod().Name}:");
205-
// }
206-
// else
207-
// {
208-
// return string.Create(CultureInfo.CurrentUICulture, $"{frame.GetMethod()}:");
209-
// }
210202

211203
return string.Create(CultureInfo.CurrentUICulture, $"{frame.GetMethod().DeclaringType.Name}::{frame.GetMethod().Name} ");
212204
}

src/Microsoft.Management.UI.Internal/ManagementList/FilterProviders/SearchTextParser.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected virtual string GetPattern()
121121
patterns.Add(rule.Pattern);
122122
}
123123

124-
patterns.Add(string.Create(CultureInfo.InvariantCulture, $"(?<{FullTextRuleGroupName}>){ValuePattern}"));
124+
patterns.Add(string.Format(CultureInfo.InvariantCulture, "(?<{0}>){1}", FullTextRuleGroupName, ValuePattern));
125125

126126
return string.Join("|", patterns.ToArray());
127127
}
@@ -199,7 +199,12 @@ public SearchableRule(string uniqueId, SelectorFilterRule selectorFilterRule, Te
199199
this.UniqueId = uniqueId;
200200
this.selectorFilterRule = selectorFilterRule;
201201
this.childRule = childRule;
202-
this.Pattern = string.Create(CultureInfo.InvariantCulture, $"(?<{uniqueId}>){Regex.Escape(selectorFilterRule.DisplayName)}\\s*:\\s*{SearchTextParser.ValuePattern}");
202+
this.Pattern = string.Format(
203+
CultureInfo.InvariantCulture,
204+
"(?<{0}>){1}\\s*:\\s*{2}",
205+
uniqueId,
206+
Regex.Escape(selectorFilterRule.DisplayName),
207+
SearchTextParser.ValuePattern);
203208
}
204209

205210
/// <summary>

src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-hex/Format-Hex.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private void ProcessString(string originalString)
296296
private static readonly Random _idGenerator = new();
297297

298298
private static string GetGroupLabel(Type inputType)
299-
=> string.Create(System.Globalization.CultureInfo.InvariantCulture, $"{inputType.Name} ({inputType.FullName}) <{_idGenerator.Next():X8}>");
299+
=> string.Format("{0} ({1}) <{2:X8}>", inputType.Name, inputType.FullName, _idGenerator.Next());
300300

301301
private void FlushInputBuffer()
302302
{

src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2594,7 +2594,8 @@ private string GenerateConnectionStringForNewRunspace()
25942594
}
25952595
else
25962596
{
2597-
return string.Create(CultureInfo.InvariantCulture, $"-connectionUri '{CodeGeneration.EscapeSingleQuotedStringContent(GetConnectionString())}'");
2597+
string connectionString = CodeGeneration.EscapeSingleQuotedStringContent(GetConnectionString());
2598+
return string.Create(CultureInfo.InvariantCulture, $"-connectionUri '{connectionString}'");
25982599
}
25992600
}
26002601

src/Microsoft.WSMan.Management/CredSSP.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ private void DisableServerSideSettings()
200200
return;
201201
}
202202

203-
string inputXml = string.Create(CultureInfo.InvariantCulture, $@"<cfg:Auth xmlns:cfg=""{helper.Service_CredSSP_XMLNmsp}""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>");
203+
string inputXml = string.Format(
204+
CultureInfo.InvariantCulture,
205+
@"<cfg:Auth xmlns:cfg=""{0}""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>",
206+
helper.Service_CredSSP_XMLNmsp);
204207

205208
m_SessionObj.Put(helper.Service_CredSSP_Uri, inputXml, 0);
206209
}
@@ -591,8 +594,11 @@ private void EnableServerSideSettings()
591594
try
592595
{
593596
XmlDocument xmldoc = new XmlDocument();
594-
string newxmlcontent = string.Create(CultureInfo.InvariantCulture, $@"<cfg:Auth xmlns:cfg=""{helper.Service_CredSSP_XMLNmsp}""><cfg:CredSSP>true</cfg:CredSSP></cfg:Auth>");
595-
597+
string newxmlcontent = string.Format(
598+
CultureInfo.InvariantCulture,
599+
@"<cfg:Auth xmlns:cfg=""{0}""><cfg:CredSSP>true</cfg:CredSSP></cfg:Auth>",
600+
helper.Service_CredSSP_XMLNmsp);
601+
596602
// push the xml string with credssp enabled
597603
xmldoc.LoadXml(m_SessionObj.Put(helper.Service_CredSSP_Uri, newxmlcontent, 0));
598604
WriteObject(xmldoc.FirstChild);

src/System.Management.Automation/DscSupport/CimDSCParser.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,9 +2532,12 @@ private static void ProcessMembers(StringBuilder sb, List<object> embeddedInstan
25322532
out embeddedInstanceType, embeddedInstanceTypes, ref enumNames);
25332533
}
25342534

2535+
string mofAttr = MapAttributesToMof(enumNames, attributes, embeddedInstanceType);
25352536
string arrayAffix = isArrayType ? "[]" : string.Empty;
25362537

2537-
sb.Append(CultureInfo.InvariantCulture, $" {MapAttributesToMof(enumNames, attributes, embeddedInstanceType)}{mofType} {member.Name}{arrayAffix};\n");
2538+
sb.Append(
2539+
CultureInfo.InvariantCulture,
2540+
$" {mofAttr}{mofType} {member.Name}{arrayAffix};\n");
25382541
}
25392542
}
25402543

@@ -3082,16 +3085,21 @@ private static void ProcessMembers(Type type, StringBuilder sb, List<object> emb
30823085
}
30833086

30843087
// TODO - validate type and name
3085-
bool isArrayType;
3086-
string embeddedInstanceType;
3087-
string mofType = MapTypeToMofType(memberType, member.Name, className, out isArrayType, out embeddedInstanceType,
3088+
string mofType = MapTypeToMofType(
3089+
memberType,
3090+
member.Name,
3091+
className,
3092+
out bool isArrayType,
3093+
out string embeddedInstanceType,
30883094
embeddedInstanceTypes);
3095+
3096+
var enumNames = memberType.IsEnum ? Enum.GetNames(memberType) : null;
3097+
string mofAttr = MapAttributesToMof(enumNames, member.GetCustomAttributes(true), embeddedInstanceType);
30893098
string arrayAffix = isArrayType ? "[]" : string.Empty;
30903099

3091-
var enumNames = memberType.IsEnum
3092-
? Enum.GetNames(memberType)
3093-
: null;
3094-
sb.Append(CultureInfo.InvariantCulture, $" {MapAttributesToMof(enumNames, member.GetCustomAttributes(true), embeddedInstanceType)}{mofType} {member.Name}{arrayAffix};\n");
3100+
sb.Append(
3101+
CultureInfo.InvariantCulture,
3102+
$" {mofAttr}{mofType} {member.Name}{arrayAffix};\n");
30953103
}
30963104
}
30973105

src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,13 @@ private void LoadData(ExtendedTypeDefinition typeDefinition, TypeInfoDataBase db
436436
ViewDefinition view = LoadViewFromObjectModel(typeDefinition.TypeNames, formatView, viewIndex++);
437437
if (view != null)
438438
{
439-
ReportTrace(string.Create(CultureInfo.InvariantCulture, $"{ControlBase.GetControlShapeName(view.mainControl)} view {view.name} is loaded from the 'FormatViewDefinition' at index {viewIndex - 1} in 'ExtendedTypeDefinition' with type name {typeDefinition.TypeName}"));
439+
ReportTrace(string.Format(
440+
CultureInfo.InvariantCulture,
441+
"{0} view {1} is loaded from the 'FormatViewDefinition' at index {2} in 'ExtendedTypeDefinition' with type name {3}",
442+
ControlBase.GetControlShapeName(view.mainControl),
443+
view.name,
444+
viewIndex - 1,
445+
typeDefinition.TypeName));
440446

441447
// we are fine, add the view to the list
442448
db.viewDefinitionsSection.viewDefinitionList.Add(view);

src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader_Views.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ private void LoadViewDefinitions(TypeInfoDataBase db, XmlNode viewDefinitionsNod
2727
ViewDefinition view = LoadView(n, index++);
2828
if (view != null)
2929
{
30-
ReportTrace(string.Create(CultureInfo.InvariantCulture, $"{ControlBase.GetControlShapeName(view.mainControl)} view {view.name} is loaded from file {view.loadingInfo.filePath}"));
30+
ReportTrace(string.Format(
31+
CultureInfo.InvariantCulture,
32+
"{0} view {1} is loaded from file {2}",
33+
ControlBase.GetControlShapeName(view.mainControl),
34+
view.name,
35+
view.loadingInfo.filePath));
3136
// we are fine, add the view to the list
3237
db.viewDefinitionsSection.viewDefinitionList.Add(view);
3338
}

src/System.Management.Automation/engine/CommandMetadata.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ internal string GetBeginBlock()
10091009
commandOrigin = string.Empty;
10101010
}
10111011

1012+
string wrappedCommand = CodeGeneration.EscapeSingleQuotedStringContent(_wrappedCommand);
10121013
if (_wrappedAnyCmdlet)
10131014
{
10141015
result = string.Create(CultureInfo.InvariantCulture, $@"
@@ -1019,7 +1020,7 @@ internal string GetBeginBlock()
10191020
$PSBoundParameters['OutBuffer'] = 1
10201021
}}
10211022
1022-
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('{CodeGeneration.EscapeSingleQuotedStringContent(_wrappedCommand)}', [System.Management.Automation.CommandTypes]::{_wrappedCommandType})
1023+
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('{wrappedCommand}', [System.Management.Automation.CommandTypes]::{_wrappedCommandType})
10231024
$scriptCmd = {{& $wrappedCmd @PSBoundParameters }}
10241025
10251026
$steppablePipeline = $scriptCmd.GetSteppablePipeline({commandOrigin})
@@ -1033,7 +1034,7 @@ internal string GetBeginBlock()
10331034
{
10341035
result = string.Create(CultureInfo.InvariantCulture, $@"
10351036
try {{
1036-
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('{CodeGeneration.EscapeSingleQuotedStringContent(_wrappedCommand)}', [System.Management.Automation.CommandTypes]::{_wrappedCommandType})
1037+
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('{wrappedCommand}', [System.Management.Automation.CommandTypes]::{_wrappedCommandType})
10371038
$PSBoundParameters.Add('$args', $args)
10381039
$scriptCmd = {{& $wrappedCmd @PSBoundParameters }}
10391040
@@ -1066,9 +1067,10 @@ internal string GetProcessBlock()
10661067

10671068
internal string GetDynamicParamBlock()
10681069
{
1070+
string wrappedCommand = CodeGeneration.EscapeSingleQuotedStringContent(_wrappedCommand);
10691071
return string.Create(CultureInfo.InvariantCulture, $@"
10701072
try {{
1071-
$targetCmd = $ExecutionContext.InvokeCommand.GetCommand('{CodeGeneration.EscapeSingleQuotedStringContent(_wrappedCommand)}', [System.Management.Automation.CommandTypes]::{_wrappedCommandType}, $PSBoundParameters)
1073+
$targetCmd = $ExecutionContext.InvokeCommand.GetCommand('{wrappedCommand}', [System.Management.Automation.CommandTypes]::{_wrappedCommandType}, $PSBoundParameters)
10721074
$dynamicParams = @($targetCmd.Parameters.GetEnumerator() | Microsoft.PowerShell.Core\Where-Object {{ $_.Value.IsDynamic }})
10731075
if ($dynamicParams.Length -gt 0)
10741076
{{

src/System.Management.Automation/engine/GetCommandCommand.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,12 @@ private PSObject GetSyntaxObject(CommandInfo command)
614614
switch (command)
615615
{
616616
case ExternalScriptInfo externalScript:
617-
replacedSyntax = string.Create(CultureInfo.InvariantCulture, $"{aliasName} (alias) -> {externalScript.Path}{Environment.NewLine}{Environment.NewLine}{command.Syntax.Replace(command.Name, aliasName)}");
617+
replacedSyntax = string.Format(
618+
"{0} (alias) -> {1}{2}{3}",
619+
aliasName,
620+
string.Format("{0}{1}", externalScript.Path, Environment.NewLine),
621+
Environment.NewLine,
622+
command.Syntax.Replace(command.Name, aliasName));
618623
break;
619624
case ApplicationInfo app:
620625
replacedSyntax = app.Path;
@@ -626,7 +631,12 @@ private PSObject GetSyntaxObject(CommandInfo command)
626631
}
627632
else
628633
{
629-
replacedSyntax = string.Create(CultureInfo.InvariantCulture, $"{aliasName} (alias) -> {command.Name}{Environment.NewLine}{command.Syntax.Replace(command.Name, aliasName)}");
634+
replacedSyntax = string.Format(
635+
"{0} (alias) -> {1}{2}{3}",
636+
aliasName,
637+
command.Name,
638+
Environment.NewLine,
639+
command.Syntax.Replace(command.Name, aliasName));
630640
}
631641

632642
break;

src/System.Management.Automation/engine/ManagementObjectAdapter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,11 @@ protected static string GetEmbeddedObjectTypeName(PropertyData pData)
577577
try
578578
{
579579
string cimType = (string)pData.Qualifiers["cimtype"].Value;
580-
result = string.Create(CultureInfo.InvariantCulture, $"{typeof(ManagementObject).FullName}#{cimType.Replace("object:", string.Empty)}");
580+
result = string.Format(
581+
CultureInfo.InvariantCulture,
582+
"{0}#{1}",
583+
typeof(ManagementObject).FullName,
584+
cimType.Replace("object:", string.Empty));
581585
}
582586
catch (ManagementException)
583587
{

src/System.Management.Automation/engine/ParameterSetInfo.cs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -238,40 +238,27 @@ private static void AppendFormatCommandParameterInfo(CommandParameterInfo parame
238238

239239
if (parameter.ParameterType == typeof(SwitchParameter))
240240
{
241-
if (parameter.IsMandatory)
242-
{
243-
result.Append($"-{parameter.Name}");
244-
}
245-
else
246-
{
247-
result.Append($"[-{parameter.Name}]");
248-
}
241+
result.AppendFormat(CultureInfo.InvariantCulture, parameter.IsMandatory ? "-{0}" : "[-{0}]", parameter.Name);
249242
}
250243
else
251244
{
252245
string parameterTypeString = GetParameterTypeString(parameter.ParameterType, parameter.Attributes);
253246

254247
if (parameter.IsMandatory)
255248
{
256-
if (parameter.Position != int.MinValue)
257-
{
258-
result.Append($"[-{parameter.Name}] <{parameterTypeString}>");
259-
}
260-
else
261-
{
262-
result.Append($"-{parameter.Name} <{parameterTypeString}>");
263-
}
249+
result.AppendFormat(
250+
CultureInfo.InvariantCulture,
251+
parameter.Position != int.MinValue ? "[-{0}] <{1}>" : "-{0} <{1}>",
252+
parameter.Name,
253+
parameterTypeString);
264254
}
265255
else
266256
{
267-
if (parameter.Position != int.MinValue)
268-
{
269-
result.Append($"[[-{parameter.Name}] <{parameterTypeString}>]");
270-
}
271-
else
272-
{
273-
result.Append($"[-{parameter.Name} <{parameterTypeString}>]");
274-
}
257+
result.AppendFormat(
258+
CultureInfo.InvariantCulture,
259+
parameter.Position != int.MinValue ? "[[-{0}] <{1}>]" : "[-{0} <{1}>]",
260+
parameter.Name,
261+
parameterTypeString);
275262
}
276263
}
277264
}

src/System.Management.Automation/engine/debugger/debugger.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5301,10 +5301,9 @@ private void DisplayScript(PSHost host, IList<PSObject> output, InvocationInfo i
53015301
for (int lineNumber = start; lineNumber <= _lines.Length && lineNumber < start + count; lineNumber++)
53025302
{
53035303
WriteLine(
5304-
lineNumber == invocationInfo.ScriptLineNumber ?
5305-
string.Create(CultureInfo.CurrentCulture, $"{lineNumber,5}:* { _lines[lineNumber - 1]}")
5306-
:
5307-
string.Create(CultureInfo.CurrentCulture, $"{lineNumber,5}: { _lines[lineNumber - 1]}"),
5304+
lineNumber == invocationInfo.ScriptLineNumber
5305+
? string.Format(CultureInfo.CurrentCulture, "{0,5}:* {1}", lineNumber, _lines[lineNumber - 1])
5306+
: string.Format(CultureInfo.CurrentCulture, "{0,5}: {1}", lineNumber, _lines[lineNumber - 1]),
53085307
host,
53095308
output);
53105309

src/System.Management.Automation/engine/hostifaces/HostUtilities.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,19 @@ runspace.ConnectionInfo is VMConnectionInfo ||
639639
!string.IsNullOrEmpty(sshConnectionInfo.UserName) &&
640640
!System.Environment.UserName.Equals(sshConnectionInfo.UserName, StringComparison.Ordinal))
641641
{
642-
return string.Create(CultureInfo.InvariantCulture, $"[{sshConnectionInfo.UserName}@{sshConnectionInfo.ComputerName}]: {basePrompt}");
642+
return string.Format(
643+
CultureInfo.InvariantCulture,
644+
"[{0}@{1}]: {2}",
645+
sshConnectionInfo.UserName,
646+
sshConnectionInfo.ComputerName,
647+
basePrompt);
643648
}
644649

645-
return string.Create(CultureInfo.InvariantCulture, $"[{runspace.ConnectionInfo.ComputerName}]: {basePrompt}");
650+
return string.Format(
651+
CultureInfo.InvariantCulture,
652+
"[{0}]: {1}",
653+
runspace.ConnectionInfo.ComputerName,
654+
basePrompt);
646655
}
647656

648657
/// <summary>

src/System.Management.Automation/engine/interpreter/BranchLabel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public RuntimeLabel(int index, int continuationStackDepth, int stackDepth)
3434

3535
public override string ToString()
3636
{
37-
return string.Create(CultureInfo.InvariantCulture, $"->{Index} C({ContinuationStackDepth}) S({StackDepth})");
37+
return string.Format(CultureInfo.InvariantCulture, "->{0} C({1}) S({2})", Index, ContinuationStackDepth, StackDepth);
3838
}
3939
}
4040

src/System.Management.Automation/engine/interpreter/LightCompiler.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ internal bool IsInsideFinallyBlock(int index)
9292

9393
public override string ToString()
9494
{
95-
return string.Create(CultureInfo.InvariantCulture, $"{(IsFault ? "fault" : "catch(" + ExceptionType.Name + ")")} [{StartIndex}-{EndIndex}] [{HandlerStartIndex}->{HandlerEndIndex}]");
95+
return string.Format(
96+
CultureInfo.InvariantCulture,
97+
"{0} [{1}-{2}] [{3}->{4}]",
98+
IsFault ? "fault" : "catch(" + ExceptionType.Name + ")",
99+
StartIndex,
100+
EndIndex,
101+
HandlerStartIndex,
102+
HandlerEndIndex);
96103
}
97104
}
98105

@@ -227,11 +234,11 @@ public override string ToString()
227234
{
228235
if (IsClear)
229236
{
230-
return string.Create(CultureInfo.InvariantCulture, $"{Index}: clear");
237+
return string.Format(CultureInfo.InvariantCulture, "{0}: clear", Index);
231238
}
232239
else
233240
{
234-
return string.Create(CultureInfo.InvariantCulture, $"{Index}: [{StartLine}-{EndLine}] '{FileName}'");
241+
return string.Format(CultureInfo.InvariantCulture, "{0}: [{1}-{2}] '{3}'", Index, StartLine, EndLine, FileName);
235242
}
236243
}
237244
}

src/System.Management.Automation/engine/interpreter/LocalVariables.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ internal Expression LoadFromArray(Expression frameData, Expression closure)
7777

7878
public override string ToString()
7979
{
80-
return string.Create(CultureInfo.InvariantCulture, $"{Index}: {(IsBoxed ? "boxed" : null)} {(InClosure ? "in closure" : null)}");
80+
return string.Format(CultureInfo.InvariantCulture, "{0}: {1} {2}", Index, IsBoxed ? "boxed" : null, InClosure ? "in closure" : null);
8181
}
8282
}
8383

0 commit comments

Comments
 (0)