Skip to content

Commit a01fb37

Browse files
authored
Use interpolated strings 8 (PowerShell#18988)
1 parent 9461030 commit a01fb37

File tree

14 files changed

+22
-50
lines changed

14 files changed

+22
-50
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ public override
190190
{
191191
string msg = StringUtil.Format(ConsoleHostUserInterfaceStrings.RankZeroArrayErrorTemplate, desc.Name);
192192
ArgumentException innerException = PSTraceSource.NewArgumentException(
193-
string.Format(CultureInfo.InvariantCulture,
194-
"descriptions[{0}].AssemblyFullName", descIndex));
193+
string.Create(CultureInfo.InvariantCulture, $"descriptions[{descIndex}].AssemblyFullName"));
195194
PromptingException e = new PromptingException(msg, innerException, "ZeroRankArray", ErrorCategory.InvalidOperation);
196195
throw e;
197196
}
@@ -203,8 +202,7 @@ public override
203202

204203
while (true)
205204
{
206-
fieldPromptList.Append(
207-
string.Format(CultureInfo.InvariantCulture, "{0}]: ", inputList.Count));
205+
fieldPromptList.AppendFormat(CultureInfo.InvariantCulture, $"{inputList.Count}]: ");
208206
bool endListInput = false;
209207
object convertedObj = null;
210208
_ = PromptForSingleItem(

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ private void WriteChoicePrompt(string[,] hotkeysAndPlainLabels,
345345
defaultStr = hotkeysAndPlainLabels[1, defaultChoice];
346346
}
347347

348-
defaultChoicesBuilder.Append(string.Format(CultureInfo.InvariantCulture,
349-
"{0}{1}", prepend, defaultStr));
348+
defaultChoicesBuilder.AppendFormat(CultureInfo.InvariantCulture, $"{prepend}{defaultStr}");
350349
prepend = ",";
351350
}
352351

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,7 @@ protected string ComputeCurrentXPath()
600600
path.Insert(0, "/");
601601
if (sf.index != -1)
602602
{
603-
path.Insert(1, string.Format(CultureInfo.InvariantCulture,
604-
"{0}[{1}]", sf.node.Name, sf.index + 1));
603+
path.Insert(1, string.Create(CultureInfo.InvariantCulture, $"{sf.node.Name}[{sf.index + 1}]"));
605604
}
606605
else
607606
{

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,8 +3365,7 @@ internal override PSMemberInfoInternalCollection<PSMemberInfo> InternalMembers
33653365
break;
33663366
default:
33673367
Diagnostics.Assert(false,
3368-
string.Format(CultureInfo.InvariantCulture,
3369-
"PSInternalMemberSet cannot process {0}", name));
3368+
string.Create(CultureInfo.InvariantCulture, $"PSInternalMemberSet cannot process {name}"));
33703369
break;
33713370
}
33723371
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,7 @@ private Collection<int> EmulatePromptForMultipleChoice(string caption,
927927
defaultStr = hotkeysAndPlainLabels[1, defaultChoice];
928928
}
929929

930-
defaultChoicesBuilder.Append(string.Format(Globalization.CultureInfo.InvariantCulture,
931-
"{0}{1}", prepend, defaultStr));
930+
defaultChoicesBuilder.AppendFormat(Globalization.CultureInfo.InvariantCulture, $"{prepend}{defaultStr}");
932931
prepend = ",";
933932
}
934933

src/System.Management.Automation/engine/parser/token.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,7 @@ internal NumberToken(InternalScriptExtent scriptExtent, object value, TokenFlags
12901290

12911291
internal override string ToDebugString(int indent)
12921292
{
1293-
return string.Format(CultureInfo.InvariantCulture,
1294-
"{0}{1}: <{2}> Value:<{3}> Type:<{4}>", StringUtil.Padding(indent), Kind, Text, _value, _value.GetType().Name);
1293+
return string.Create(CultureInfo.InvariantCulture, $"{StringUtil.Padding(indent)}{Kind}: <{Text}> Value:<{_value}> Type:<{_value.GetType().Name}>");
12951294
}
12961295

12971296
/// <summary>
@@ -1332,8 +1331,7 @@ internal ParameterToken(InternalScriptExtent scriptExtent, string parameterName,
13321331

13331332
internal override string ToDebugString(int indent)
13341333
{
1335-
return string.Format(CultureInfo.InvariantCulture,
1336-
"{0}{1}: <-{2}{3}>", StringUtil.Padding(indent), Kind, _parameterName, _usedColon ? ":" : string.Empty);
1334+
return string.Create(CultureInfo.InvariantCulture, $"{StringUtil.Padding(indent)}{Kind}: <-{_parameterName}{(_usedColon ? ":" : string.Empty)}>");
13371335
}
13381336
}
13391337

@@ -1360,8 +1358,7 @@ internal VariableToken(InternalScriptExtent scriptExtent, VariablePath path, Tok
13601358

13611359
internal override string ToDebugString(int indent)
13621360
{
1363-
return string.Format(CultureInfo.InvariantCulture,
1364-
"{0}{1}: <{2}> Name:<{3}>", StringUtil.Padding(indent), Kind, Text, Name);
1361+
return string.Create(CultureInfo.InvariantCulture, $"{StringUtil.Padding(indent)}{Kind}: <{Text}> Name:<{Name}>");
13651362
}
13661363
}
13671364

@@ -1383,8 +1380,7 @@ internal StringToken(InternalScriptExtent scriptExtent, TokenKind kind, TokenFla
13831380

13841381
internal override string ToDebugString(int indent)
13851382
{
1386-
return string.Format(CultureInfo.InvariantCulture,
1387-
"{0}{1}: <{2}> Value:<{3}>", StringUtil.Padding(indent), Kind, Text, Value);
1383+
return string.Create(CultureInfo.InvariantCulture, $"{StringUtil.Padding(indent)}{Kind}: <{Text}> Value:<{Value}>");
13881384
}
13891385
}
13901386

src/System.Management.Automation/engine/remoting/client/Job.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,8 +3307,7 @@ protected void ProcessJobFailure(ExecutionCmdletHelper helper, out Exception fai
33073307
errorId = "InvalidSessionState";
33083308
if (!string.IsNullOrEmpty(failureException.Source))
33093309
{
3310-
errorId = string.Format(System.Globalization.CultureInfo.InvariantCulture,
3311-
"{0},{1}", errorId, failureException.Source);
3310+
errorId = string.Create(System.Globalization.CultureInfo.InvariantCulture, $"{errorId},{failureException.Source}");
33123311
}
33133312
}
33143313

src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ internal static string ParseEscapeWSManErrorMessage(string errorMessage)
202202
Collection<PSToken> tokens = PSParser.Tokenize(errorMessage, out parserErrors);
203203
if (parserErrors.Count > 0)
204204
{
205-
tracer.WriteLine(string.Format(CultureInfo.InvariantCulture,
206-
"There were errors parsing string '{0}'", errorMessage);
205+
tracer.WriteLine(string.Create(CultureInfo.InvariantCulture, $"There were errors parsing string '{errorMessage}'");
207206
return errorMessage;
208207
}
209208
@@ -1399,25 +1398,17 @@ private void Initialize(Uri connectionUri, WSManConnectionInfo connectionInfo)
13991398
if (string.IsNullOrEmpty(connectionUri.Query))
14001399
{
14011400
// if there is no query string already, create one..see RFC 3986
1402-
connectionStr = string.Format(CultureInfo.InvariantCulture,
1403-
"{0}?PSVersion={1}{2}",
1401+
connectionStr = string.Create(CultureInfo.InvariantCulture, $"{connectionStr.TrimEnd('/')}?PSVersion={PSVersionInfo.PSVersion}{additionalUriSuffixString}");
14041402
// Trimming the last '/' as this will allow WSMan to
14051403
// properly apply URLPrefix.
14061404
// Ex: http://localhost?PSVersion=2.0 will be converted
14071405
// to http://localhost:<port>/<urlprefix>?PSVersion=2.0
14081406
// by WSMan
1409-
connectionStr.TrimEnd('/'),
1410-
PSVersionInfo.PSVersion,
1411-
additionalUriSuffixString);
14121407
}
14131408
else
14141409
{
14151410
// if there is already a query string, append using & .. see RFC 3986
1416-
connectionStr = string.Format(CultureInfo.InvariantCulture,
1417-
"{0};PSVersion={1}{2}",
1418-
connectionStr,
1419-
PSVersionInfo.PSVersion,
1420-
additionalUriSuffixString);
1411+
connectionStr = string.Create(CultureInfo.InvariantCulture, $"{connectionStr};PSVersion={PSVersionInfo.PSVersion}{additionalUriSuffixString}");
14211412
}
14221413

14231414
WSManNativeApi.BaseWSManAuthenticationCredentials authCredentials;

src/System.Management.Automation/engine/runtime/Binding/Binders.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7577,8 +7577,7 @@ internal PSCreateInstanceBinder(CallInfo callInfo, PSMethodInvocationConstraints
75777577

75787578
public override string ToString()
75797579
{
7580-
return string.Format(CultureInfo.InvariantCulture,
7581-
"PSCreateInstanceBinder: ver:{0} args:{1} constraints:<{2}>", _version, _callInfo.ArgumentCount, _constraints != null ? _constraints.ToString() : string.Empty);
7580+
return string.Create(CultureInfo.InvariantCulture, $"PSCreateInstanceBinder: ver:{_version} args:{_callInfo.ArgumentCount} constraints:<{(_constraints != null ? _constraints : string.Empty)}>");
75827581
}
75837582

75847583
public override DynamicMetaObject FallbackCreateInstance(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)

src/System.Management.Automation/help/AliasHelpInfo.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ private AliasHelpInfo(AliasInfo aliasInfo)
4040
}
4141

4242
_fullHelpObject.TypeNames.Clear();
43-
_fullHelpObject.TypeNames.Add(string.Format(Globalization.CultureInfo.InvariantCulture,
44-
"AliasHelpInfo#{0}", Name));
43+
_fullHelpObject.TypeNames.Add(string.Create(Globalization.CultureInfo.InvariantCulture, $"AliasHelpInfo#{Name}"));
4544
_fullHelpObject.TypeNames.Add("AliasHelpInfo");
4645
_fullHelpObject.TypeNames.Add("HelpInfo");
4746
}

src/System.Management.Automation/help/BaseCommandHelpInfo.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ internal Uri LookupUriFromCommandInfo()
214214
string commandToSearch = commandName;
215215
if (!string.IsNullOrEmpty(moduleName))
216216
{
217-
commandToSearch = string.Format(CultureInfo.InvariantCulture,
218-
"{0}\\{1}", moduleName, commandName);
217+
commandToSearch = string.Create(CultureInfo.InvariantCulture, $"{moduleName}\\{commandName}");
219218
}
220219

221220
ExecutionContext context = LocalPipeline.GetExecutionContextFromTLS();

src/System.Management.Automation/help/CommandHelpProvider.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,15 +950,13 @@ private void AddToCommandCache(string mshSnapInId, string cmdletName, MamlComman
950950

951951
// Add snapin qualified type name for this command at the top..
952952
// this will enable customizations of the help object.
953-
helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture,
954-
"MamlCommandHelpInfo#{0}#{1}", mshSnapInId, cmdletName));
953+
helpInfo.FullHelp.TypeNames.Insert(0, string.Create(CultureInfo.InvariantCulture, $"MamlCommandHelpInfo#{mshSnapInId}#{cmdletName}"));
955954

956955
if (!string.IsNullOrEmpty(mshSnapInId))
957956
{
958957
key = mshSnapInId + "\\" + key;
959958
// Add snapin name to the typenames of this object
960-
helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture,
961-
"MamlCommandHelpInfo#{0}", mshSnapInId));
959+
helpInfo.FullHelp.TypeNames.Insert(1, string.Create(CultureInfo.InvariantCulture, $"MamlCommandHelpInfo#{mshSnapInId}"));
962960
}
963961

964962
AddCache(key, helpInfo);

src/System.Management.Automation/help/HelpCommands.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,7 @@ public static string GetHelpUri(PSObject commandInfoPSObject)
821821
string cmdName = cmdInfo.Name;
822822
if (!string.IsNullOrEmpty(cmdInfo.ModuleName))
823823
{
824-
cmdName = string.Format(CultureInfo.InvariantCulture,
825-
"{0}\\{1}", cmdInfo.ModuleName, cmdInfo.Name);
824+
cmdName = string.Create(CultureInfo.InvariantCulture, $"{cmdInfo.ModuleName}\\{cmdInfo.Name}");
826825
}
827826

828827
if (DoesCurrentRunspaceIncludeCoreHelpCmdlet())

src/System.Management.Automation/help/ProviderHelpProvider.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,12 @@ private void LoadHelpFile(ProviderInfo providerInfo)
236236
this.HelpSystem.TraceErrors(helpInfo.Errors);
237237
// Add snapin qualified type name for this command..
238238
// this will enable customizations of the help object.
239-
helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture,
240-
"ProviderHelpInfo#{0}#{1}", providerInfo.PSSnapInName, helpInfo.Name));
239+
helpInfo.FullHelp.TypeNames.Insert(0, string.Create(CultureInfo.InvariantCulture, $"ProviderHelpInfo#{providerInfo.PSSnapInName}#{helpInfo.Name}"));
241240

242241
if (!string.IsNullOrEmpty(providerInfo.PSSnapInName))
243242
{
244243
helpInfo.FullHelp.Properties.Add(new PSNoteProperty("PSSnapIn", providerInfo.PSSnapIn));
245-
helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture,
246-
"ProviderHelpInfo#{0}", providerInfo.PSSnapInName));
244+
helpInfo.FullHelp.TypeNames.Insert(1, string.Create(CultureInfo.InvariantCulture, $"ProviderHelpInfo#{providerInfo.PSSnapInName}"));
247245
}
248246

249247
AddCache(providerInfo.PSSnapInName + "\\" + helpInfo.Name, helpInfo);

0 commit comments

Comments
 (0)