From b85fe99f5aa3bed704da0669a5f44140854e7f75 Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Fri, 20 Jan 2023 18:22:10 +0100
Subject: [PATCH] Use interpolated strings 2 (#18978)
---
.../GetCounterCommand.cs | 2 +-
.../GetEventCommand.cs | 10 ++---
.../ImportCounterCommand.cs | 2 +-
.../management/GetComputerInfoCommand.cs | 2 +-
.../commands/management/Navigation.cs | 2 +-
.../commands/utility/CsvCommands.cs | 2 +-
.../FormatAndOutput/format-hex/Format-Hex.cs | 2 +-
.../commands/utility/Group-Object.cs | 4 +-
.../utility/ImplicitRemotingCommands.cs | 37 ++++++-------------
.../commands/utility/UtilityCommon.cs | 2 +-
.../WebCmdlet/Common/ContentHelper.Common.cs | 2 +-
.../Common/InvokeRestMethodCommand.Common.cs | 2 +-
.../Common/WebRequestPSCmdlet.Common.cs | 10 ++---
.../CoreCLR/WebResponseHelper.CoreClr.cs | 2 +-
.../commands/utility/WebCmdlet/PSUserAgent.cs | 14 +++----
.../commands/utility/XmlCommands.cs | 2 +-
.../host/msh/ConsoleControl.cs | 30 +++++++--------
.../host/msh/ConsoleHostRawUserInterface.cs | 7 ++--
.../msh/ConsoleHostUserInterfacePrompt.cs | 6 +--
...ConsoleHostUserInterfacePromptForChoice.cs | 2 +-
.../host/msh/UpdatesNotification.cs | 2 +-
21 files changed, 62 insertions(+), 82 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
index f04c8ceff0..0122ad1941 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
@@ -248,7 +248,7 @@ namespace Microsoft.PowerShell.Commands
break;
default:
- Debug.Fail(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", ParameterSetName));
+ Debug.Fail(string.Create(CultureInfo.InvariantCulture, $"Invalid parameter set name: {ParameterSetName}"));
break;
}
}
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
index 587a63683a..8f7e42dd9a 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
@@ -396,7 +396,7 @@ namespace Microsoft.PowerShell.Commands
break;
default:
- WriteDebug(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", ParameterSetName));
+ WriteDebug(string.Create(CultureInfo.InvariantCulture, $"Invalid parameter set name: {ParameterSetName}"));
break;
}
}
@@ -492,7 +492,7 @@ namespace Microsoft.PowerShell.Commands
foreach (string log in _providersByLogMap.Keys)
{
logQuery = new EventLogQuery(log, PathType.LogName, AddProviderPredicatesToFilter(_providersByLogMap[log]));
- WriteVerbose(string.Format(CultureInfo.InvariantCulture, "Log {0} will be queried", log));
+ WriteVerbose(string.Create(CultureInfo.InvariantCulture, $"Log {log} will be queried"));
}
}
@@ -680,7 +680,7 @@ namespace Microsoft.PowerShell.Commands
foreach (string resolvedPath in resolvedPaths)
{
_resolvedPaths.Add(resolvedPath);
- WriteVerbose(string.Format(CultureInfo.InvariantCulture, "Found file {0}", resolvedPath));
+ WriteVerbose(string.Create(CultureInfo.InvariantCulture, $"Found file {resolvedPath}"));
}
}
@@ -908,7 +908,7 @@ namespace Microsoft.PowerShell.Commands
break;
default:
- WriteDebug(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", ParameterSetName));
+ WriteDebug(string.Create(CultureInfo.InvariantCulture, $"Invalid parameter set name: {ParameterSetName}"));
break;
}
@@ -2047,7 +2047,7 @@ namespace Microsoft.PowerShell.Commands
||
(wildProvPattern.IsMatch(provName)))
{
- WriteVerbose(string.Format(CultureInfo.InvariantCulture, "Found matching provider: {0}", provName));
+ WriteVerbose(string.Create(CultureInfo.InvariantCulture, $"Found matching provider: {provName}"));
AddLogsForProviderToInternalMap(eventLogSession, provName);
bMatched = true;
}
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs
index d571df3408..ed4cdb51ff 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs
@@ -240,7 +240,7 @@ namespace Microsoft.PowerShell.Commands
break;
default:
- Debug.Assert(false, string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", ParameterSetName));
+ Debug.Assert(false, $"Invalid parameter set name: {ParameterSetName}");
break;
}
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs
index 7f69d6defd..4756928292 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs
@@ -248,7 +248,7 @@ namespace Microsoft.PowerShell.Commands
try
{
var halPath = CIMHelper.EscapePath(System.IO.Path.Combine(systemDirectory, "hal.dll"));
- var query = string.Format("SELECT * FROM CIM_DataFile Where Name='{0}'", halPath);
+ var query = string.Create(CultureInfo.InvariantCulture, $"SELECT * FROM CIM_DataFile Where Name='{halPath}'");
var instance = session.QueryFirstInstance(query);
if (instance != null)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs
index 9e81db105b..6699521731 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs
@@ -618,7 +618,7 @@ namespace Microsoft.PowerShell.Commands
break;
default:
- Dbg.Diagnostics.Assert(false, string.Format(System.Globalization.CultureInfo.InvariantCulture, "One of the predefined parameter sets should have been specified, instead we got: {0}", ParameterSetName));
+ Dbg.Diagnostics.Assert(false, string.Create(System.Globalization.CultureInfo.InvariantCulture, $"One of the predefined parameter sets should have been specified, instead we got: {ParameterSetName}"));
break;
}
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
index 3557946b24..a447a8983b 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs
@@ -1151,7 +1151,7 @@ namespace Microsoft.PowerShell.Commands
temp = temp.Substring(4);
}
- type = string.Format(System.Globalization.CultureInfo.InvariantCulture, "#TYPE {0}", temp);
+ type = string.Create(System.Globalization.CultureInfo.InvariantCulture, $"#TYPE {temp}");
}
return type;
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-hex/Format-Hex.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-hex/Format-Hex.cs
index de73b2155a..b6a6d02439 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-hex/Format-Hex.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-hex/Format-Hex.cs
@@ -296,7 +296,7 @@ namespace Microsoft.PowerShell.Commands
private static readonly Random _idGenerator = new();
private static string GetGroupLabel(Type inputType)
- => string.Format("{0} ({1}) <{2:X8}>", inputType.Name, inputType.FullName, _idGenerator.Next());
+ => string.Create(System.Globalization.CultureInfo.InvariantCulture, $"{inputType.Name} ({inputType.FullName}) <{_idGenerator.Next():X8}>");
private void FlushInputBuffer()
{
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Group-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Group-Object.cs
index 379865e850..51f8f0a601 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Group-Object.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Group-Object.cs
@@ -153,7 +153,7 @@ namespace Microsoft.PowerShell.Commands
foreach (object item in propertyValueItems)
{
- sb.AppendFormat(CultureInfo.InvariantCulture, "{0}, ", item.ToString());
+ sb.Append(CultureInfo.InvariantCulture, $"{item}, ");
}
sb = sb.Length > length ? sb.Remove(sb.Length - 2, 2) : sb;
@@ -161,7 +161,7 @@ namespace Microsoft.PowerShell.Commands
}
else
{
- sb.AppendFormat(CultureInfo.InvariantCulture, "{0}, ", propValuePropertyValue.ToString());
+ sb.Append(CultureInfo.InvariantCulture, $"{propValuePropertyValue}, ");
}
}
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs
index c6197a4b7b..ed21408c92 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs
@@ -2247,13 +2247,13 @@ function Get-PSImplicitRemotingSessionOption
RunspaceConnectionInfo runspaceConnectionInfo = _remoteRunspaceInfo.Runspace.ConnectionInfo as RunspaceConnectionInfo;
if (runspaceConnectionInfo != null)
{
- result.AppendFormat(null, "-Culture '{0}' ", CodeGeneration.EscapeSingleQuotedStringContent(runspaceConnectionInfo.Culture.ToString()));
- result.AppendFormat(null, "-UICulture '{0}' ", CodeGeneration.EscapeSingleQuotedStringContent(runspaceConnectionInfo.UICulture.ToString()));
+ result.Append(null, $"-Culture '{CodeGeneration.EscapeSingleQuotedStringContent(runspaceConnectionInfo.Culture.ToString())}' ");
+ result.Append(null, $"-UICulture '{CodeGeneration.EscapeSingleQuotedStringContent(runspaceConnectionInfo.UICulture.ToString())}' ");
- result.AppendFormat(null, "-CancelTimeOut {0} ", runspaceConnectionInfo.CancelTimeout);
- result.AppendFormat(null, "-IdleTimeOut {0} ", runspaceConnectionInfo.IdleTimeout);
- result.AppendFormat(null, "-OpenTimeOut {0} ", runspaceConnectionInfo.OpenTimeout);
- result.AppendFormat(null, "-OperationTimeOut {0} ", runspaceConnectionInfo.OperationTimeout);
+ result.Append(null, $"-CancelTimeOut {runspaceConnectionInfo.CancelTimeout} ");
+ result.Append(null, $"-IdleTimeOut {runspaceConnectionInfo.IdleTimeout} ");
+ result.Append(null, $"-OpenTimeOut {runspaceConnectionInfo.OpenTimeout} ");
+ result.Append(null, $"-OperationTimeOut {runspaceConnectionInfo.OperationTimeout} ");
}
WSManConnectionInfo wsmanConnectionInfo = _remoteRunspaceInfo.Runspace.ConnectionInfo as WSManConnectionInfo;
@@ -2275,33 +2275,18 @@ function Get-PSImplicitRemotingSessionOption
if (wsmanConnectionInfo.MaximumReceivedDataSizePerCommand.HasValue)
{
- result.AppendFormat(
- CultureInfo.InvariantCulture,
- "-MaximumReceivedDataSizePerCommand {0} ",
- wsmanConnectionInfo.MaximumReceivedDataSizePerCommand.Value);
+ result.Append(CultureInfo.InvariantCulture, $"-MaximumReceivedDataSizePerCommand {wsmanConnectionInfo.MaximumReceivedDataSizePerCommand.Value} ");
}
if (wsmanConnectionInfo.MaximumReceivedObjectSize.HasValue)
{
- result.AppendFormat(
- CultureInfo.InvariantCulture,
- "-MaximumReceivedObjectSize {0} ",
- wsmanConnectionInfo.MaximumReceivedObjectSize.Value);
+ result.Append(CultureInfo.InvariantCulture, $"-MaximumReceivedObjectSize {wsmanConnectionInfo.MaximumReceivedObjectSize.Value} ");
}
- result.AppendFormat(
- CultureInfo.InvariantCulture,
- "-MaximumRedirection {0} ",
- wsmanConnectionInfo.MaximumConnectionRedirectionCount);
+ result.Append(CultureInfo.InvariantCulture, $"-MaximumRedirection {wsmanConnectionInfo.MaximumConnectionRedirectionCount} ");
- result.AppendFormat(
- CultureInfo.InvariantCulture,
- "-ProxyAccessType {0} ",
- wsmanConnectionInfo.ProxyAccessType.ToString());
- result.AppendFormat(
- CultureInfo.InvariantCulture,
- "-ProxyAuthentication {0} ",
- wsmanConnectionInfo.ProxyAuthentication.ToString());
+ result.Append(CultureInfo.InvariantCulture, $"-ProxyAccessType {wsmanConnectionInfo.ProxyAccessType} ");
+ result.Append(CultureInfo.InvariantCulture, $"-ProxyAuthentication {wsmanConnectionInfo.ProxyAuthentication} ");
result.Append(this.GenerateProxyCredentialParameter(wsmanConnectionInfo));
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UtilityCommon.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UtilityCommon.cs
index 327e6f19c5..1e3cc03875 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UtilityCommon.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UtilityCommon.cs
@@ -215,7 +215,7 @@ namespace Microsoft.PowerShell.Commands
///
/// Gets the hexadecimal representation of the value.
///
- public string HexOffset { get => string.Format(CultureInfo.CurrentCulture, "{0:X16}", Offset64); }
+ public string HexOffset => string.Create(CultureInfo.CurrentCulture, $"{Offset64:X16}");
///
/// Gets the type of the input objects used to create the .
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs
index bf4693c1e3..d44828acd3 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs
@@ -32,7 +32,7 @@ namespace Microsoft.PowerShell.Commands
{
int statusCode = WebResponseHelper.GetStatusCode(response);
string statusDescription = WebResponseHelper.GetStatusDescription(response);
- raw.AppendFormat("{0} {1} {2}", protocol, statusCode, statusDescription);
+ raw.Append($"{protocol} {statusCode} {statusDescription}");
raw.AppendLine();
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
index d128800af6..242f380d94 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
@@ -116,7 +116,7 @@ namespace Microsoft.PowerShell.Commands
}
// NOTE: Tests use this verbose output to verify the encoding.
- WriteVerbose(string.Format(System.Globalization.CultureInfo.InvariantCulture, $"Content encoding: {encodingVerboseName}"));
+ WriteVerbose(string.Create(System.Globalization.CultureInfo.InvariantCulture, $"Content encoding: {encodingVerboseName}"));
bool convertSuccess = false;
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
index 73eb34013a..beb9ad93e7 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
@@ -744,7 +744,7 @@ namespace Microsoft.PowerShell.Commands
encodedValue = WebUtility.UrlEncode(value.ToString());
}
- bodyBuilder.AppendFormat("{0}={1}", encodedKey, encodedValue);
+ bodyBuilder.Append($"{encodedKey}={encodedValue}");
}
return bodyBuilder.ToString();
@@ -768,14 +768,14 @@ namespace Microsoft.PowerShell.Commands
private string GetBasicAuthorizationHeader()
{
var password = new NetworkCredential(null, Credential.Password).Password;
- string unencoded = string.Format($"{Credential.UserName}:{password}");
+ string unencoded = string.Create(CultureInfo.InvariantCulture, $"{Credential.UserName}:{password}");
byte[] bytes = Encoding.UTF8.GetBytes(unencoded);
- return string.Format($"Basic {Convert.ToBase64String(bytes)}");
+ return string.Create(CultureInfo.InvariantCulture, $"Basic {Convert.ToBase64String(bytes)}");
}
private string GetBearerAuthorizationHeader()
{
- return string.Format($"Bearer {new NetworkCredential(string.Empty, Token).Password}");
+ return string.Create(CultureInfo.InvariantCulture, $"Bearer {new NetworkCredential(string.Empty, Token).Password}");
}
private void ProcessAuthentication()
@@ -790,7 +790,7 @@ namespace Microsoft.PowerShell.Commands
}
else
{
- Diagnostics.Assert(false, string.Format($"Unrecognized Authentication value: {Authentication}"));
+ Diagnostics.Assert(false, string.Create(CultureInfo.InvariantCulture, $"Unrecognized Authentication value: {Authentication}"));
}
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebResponseHelper.CoreClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebResponseHelper.CoreClr.cs
index 43dee2fa02..9de4311e43 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebResponseHelper.CoreClr.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebResponseHelper.CoreClr.cs
@@ -34,7 +34,7 @@ namespace Microsoft.PowerShell.Commands
return headers;
}
- internal static string GetProtocol(HttpResponseMessage response) => string.Format(CultureInfo.InvariantCulture, $"HTTP/{response.Version}");
+ internal static string GetProtocol(HttpResponseMessage response) => string.Create(CultureInfo.InvariantCulture, $"HTTP/{response.Version}");
internal static int GetStatusCode(HttpResponseMessage response) => (int)response.StatusCode;
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/PSUserAgent.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/PSUserAgent.cs
index 9ccd7e624c..e4312e7497 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/PSUserAgent.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/PSUserAgent.cs
@@ -17,36 +17,36 @@ namespace Microsoft.PowerShell.Commands
private static string s_windowsUserAgent;
// Format the user-agent string from the various component parts
- internal static string UserAgent => string.Format(CultureInfo.InvariantCulture, $"{Compatibility} ({PlatformName}; {OS}; {Culture}) {App}");
+ internal static string UserAgent => string.Create(CultureInfo.InvariantCulture, $"{Compatibility} ({PlatformName}; {OS}; {Culture}) {App}");
///
/// Useragent string for InternetExplorer (9.0).
///
- public static string InternetExplorer => string.Format(CultureInfo.InvariantCulture, $"{Compatibility} (compatible; MSIE 9.0; {PlatformName}; {OS}; {Culture})");
+ public static string InternetExplorer => string.Create(CultureInfo.InvariantCulture, $"{Compatibility} (compatible; MSIE 9.0; {PlatformName}; {OS}; {Culture})");
///
/// Useragent string for Firefox (4.0).
///
- public static string FireFox => string.Format(CultureInfo.InvariantCulture, $"{Compatibility} ({PlatformName}; {OS}; {Culture}) Gecko/20100401 Firefox/4.0");
+ public static string FireFox => string.Create(CultureInfo.InvariantCulture, $"{Compatibility} ({PlatformName}; {OS}; {Culture}) Gecko/20100401 Firefox/4.0");
///
/// Useragent string for Chrome (7.0).
///
- public static string Chrome => string.Format(CultureInfo.InvariantCulture, $"{Compatibility} ({PlatformName}; {OS}; {Culture}) AppleWebKit/534.6 (KHTML, like Gecko) Chrome/7.0.500.0 Safari/534.6");
+ public static string Chrome => string.Create(CultureInfo.InvariantCulture, $"{Compatibility} ({PlatformName}; {OS}; {Culture}) AppleWebKit/534.6 (KHTML, like Gecko) Chrome/7.0.500.0 Safari/534.6");
///
/// Useragent string for Opera (9.0).
///
- public static string Opera => string.Format(CultureInfo.InvariantCulture, $"Opera/9.70 ({PlatformName}; {OS}; {Culture}) Presto/2.2.1");
+ public static string Opera => string.Create(CultureInfo.InvariantCulture, $"Opera/9.70 ({PlatformName}; {OS}; {Culture}) Presto/2.2.1");
///
/// Useragent string for Safari (5.0).
///
- public static string Safari => string.Format(CultureInfo.InvariantCulture, $"{Compatibility} ({PlatformName}; {OS}; {Culture}) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16");
+ public static string Safari => string.Create(CultureInfo.InvariantCulture, $"{Compatibility} ({PlatformName}; {OS}; {Culture}) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16");
internal static string Compatibility => "Mozilla/5.0";
- internal static string App => string.Format(CultureInfo.InvariantCulture, $"PowerShell/{PSVersionInfo.PSVersion}");
+ internal static string App => string.Create(CultureInfo.InvariantCulture, $"PowerShell/{PSVersionInfo.PSVersion}");
internal static string PlatformName
{
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs
index f39242e101..8873676c61 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs
@@ -439,7 +439,7 @@ namespace Microsoft.PowerShell.Commands
}
else
{
- WriteObject(string.Format(CultureInfo.InvariantCulture, "", Encoding.UTF8.WebName));
+ WriteObject(string.Create(CultureInfo.InvariantCulture, $""));
WriteObject("");
}
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
index e5197d77ae..43eb27b86e 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
@@ -109,7 +109,7 @@ namespace Microsoft.PowerShell
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "{0},{1}", X, Y);
+ return string.Create(CultureInfo.InvariantCulture, $"{X},{Y}");
}
}
@@ -161,7 +161,7 @@ namespace Microsoft.PowerShell
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", Left, Top, Right, Bottom);
+ return string.Create(CultureInfo.InvariantCulture, $"{Left},{Top},{Right},{Bottom}");
}
}
@@ -192,7 +192,7 @@ namespace Microsoft.PowerShell
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "Size: {0}, Visible: {1}", Size, Visible);
+ return string.Create(CultureInfo.InvariantCulture, $"Size: {Size}, Visible: {Visible}");
}
}
@@ -1249,8 +1249,7 @@ namespace Microsoft.PowerShell
{
if (firstLeftTrailingRow >= 0)
{
- throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]",
- firstLeftTrailingRow, contentsRegion.Left));
+ throw PSTraceSource.NewArgumentException(string.Create(CultureInfo.InvariantCulture, $"contents[{firstLeftTrailingRow}, {contentsRegion.Left}]"));
}
}
else
@@ -1265,8 +1264,7 @@ namespace Microsoft.PowerShell
if (leftExisting[r, 0].BufferCellType == BufferCellType.Leading ^
contents[r, contentsRegion.Left].BufferCellType == BufferCellType.Trailing)
{
- throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]",
- r, contentsRegion.Left));
+ throw PSTraceSource.NewArgumentException(string.Create(CultureInfo.InvariantCulture, $"contents[{r}, {contentsRegion.Left}]"));
}
}
}
@@ -1275,8 +1273,7 @@ namespace Microsoft.PowerShell
{
if (firstRightLeadingRow >= 0)
{
- throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]",
- firstRightLeadingRow, contentsRegion.Right));
+ throw PSTraceSource.NewArgumentException(string.Create(CultureInfo.InvariantCulture, $"contents[{firstRightLeadingRow}, {contentsRegion.Right}]"));
}
}
else
@@ -1291,8 +1288,7 @@ namespace Microsoft.PowerShell
if (rightExisting[r, 0].BufferCellType == BufferCellType.Leading ^
contents[r, contentsRegion.Right].BufferCellType == BufferCellType.Leading)
{
- throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]",
- r, contentsRegion.Right));
+ throw PSTraceSource.NewArgumentException(string.Create(CultureInfo.InvariantCulture, $"contents[{r}, {contentsRegion.Right}]"));
}
}
}
@@ -1312,7 +1308,7 @@ namespace Microsoft.PowerShell
contents[r, c].Character != 0)
{
// trailing character is not 0
- throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]", r, c));
+ throw PSTraceSource.NewArgumentException(string.Create(CultureInfo.InvariantCulture, $"contents[{r}, {c}]"));
}
if (contents[r, c].BufferCellType == BufferCellType.Leading)
@@ -1327,7 +1323,7 @@ namespace Microsoft.PowerShell
{
// for a 2 cell character, either there is no trailing BufferCell or
// the trailing BufferCell's character is not 0
- throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]", r, c));
+ throw PSTraceSource.NewArgumentException(string.Create(CultureInfo.InvariantCulture, $"contents[{r}, {c}]"));
}
}
}
@@ -1522,7 +1518,7 @@ namespace Microsoft.PowerShell
// to write is larger than bufferLimit. In that case, the algorithm writes one row
// at a time => bufferSize.Y == 1. Then, we can safely leave bufferSize.Y unchanged
// to retry with a smaller bufferSize.X.
- Dbg.Assert(bufferSize.Y == 1, string.Format(CultureInfo.InvariantCulture, "bufferSize.Y should be 1, but is {0}", bufferSize.Y));
+ Dbg.Assert(bufferSize.Y == 1, string.Create(CultureInfo.InvariantCulture, $"bufferSize.Y should be 1, but is {bufferSize.Y}"));
bufferSize.X = (short)Math.Min(colsRemaining, bufferLimit);
continue;
}
@@ -1650,7 +1646,7 @@ namespace Microsoft.PowerShell
// to write is larger than bufferLimit. In that case, the algorithm writes one row
// at a time => bufferSize.Y == 1. Then, we can safely leave bufferSize.Y unchanged
// to retry with a smaller bufferSize.X.
- Dbg.Assert(bufferSize.Y == 1, string.Format(CultureInfo.InvariantCulture, "bufferSize.Y should be 1, but is {0}", bufferSize.Y));
+ Dbg.Assert(bufferSize.Y == 1, string.Create(CultureInfo.InvariantCulture, $"bufferSize.Y should be 1, but is {bufferSize.Y}"));
bufferSize.X = (short)Math.Min(colsRemaining, bufferLimit);
continue;
}
@@ -1975,7 +1971,7 @@ namespace Microsoft.PowerShell
// to write is larger than bufferLimit. In that case, the algorithm reads one row
// at a time => bufferSize.Y == 1. Then, we can safely leave bufferSize.Y unchanged
// to retry with a smaller bufferSize.X.
- Dbg.Assert(bufferSize.Y == 1, string.Format(CultureInfo.InvariantCulture, "bufferSize.Y should be 1, but is {0}", bufferSize.Y));
+ Dbg.Assert(bufferSize.Y == 1, string.Create(CultureInfo.InvariantCulture, $"bufferSize.Y should be 1, but is {bufferSize.Y}"));
bufferSize.X = (short)Math.Min(colsRemaining, bufferLimit);
continue;
}
@@ -2145,7 +2141,7 @@ namespace Microsoft.PowerShell
// to write is larger than bufferLimit. In that case, the algorithm reads one row
// at a time => bufferSize.Y == 1. Then, we can safely leave bufferSize.Y unchanged
// to retry with a smaller bufferSize.X.
- Dbg.Assert(bufferSize.Y == 1, string.Format(CultureInfo.InvariantCulture, "bufferSize.Y should be 1, but is {0}", bufferSize.Y));
+ Dbg.Assert(bufferSize.Y == 1, string.Create(CultureInfo.InvariantCulture, $"bufferSize.Y should be 1, but is {bufferSize.Y}"));
bufferSize.X = (short)Math.Min(colsRemaining, bufferLimit);
continue;
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
index f5937d21e0..a0d654759b 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
@@ -639,8 +639,7 @@ namespace Microsoft.PowerShell
{
int actualNumberOfInput = ConsoleControl.ReadConsoleInput(handle, ref inputRecords);
Dbg.Assert(actualNumberOfInput == 1,
- string.Format(CultureInfo.InvariantCulture, "ReadConsoleInput returns {0} number of input event records",
- actualNumberOfInput));
+ string.Create(CultureInfo.InvariantCulture, $"ReadConsoleInput returns {actualNumberOfInput} number of input event records"));
if (actualNumberOfInput == 1)
{
if (((ConsoleControl.InputRecordEventTypes)inputRecords[0].EventType) ==
@@ -1532,7 +1531,7 @@ namespace Microsoft.PowerShell
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "{0},{1}", X, Y);
+ return string.Create(CultureInfo.InvariantCulture, $"{X},{Y}");
}
}
@@ -1548,7 +1547,7 @@ namespace Microsoft.PowerShell
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", Left, Top, Right, Bottom);
+ return string.Create(CultureInfo.InvariantCulture, $"{Left},{Top},{Right},{Bottom}");
}
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs
index 58cd171cd2..7b81bb8a97 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePrompt.cs
@@ -140,7 +140,7 @@ namespace Microsoft.PowerShell
{
throw PSTraceSource.NewArgumentException(nameof(descriptions),
ConsoleHostUserInterfaceStrings.NullErrorTemplate,
- string.Format(CultureInfo.InvariantCulture, "descriptions[{0}]", descIndex));
+ string.Create(CultureInfo.InvariantCulture, $"descriptions[{descIndex}]"));
}
PSObject inputPSObject = null;
@@ -152,7 +152,7 @@ namespace Microsoft.PowerShell
if (string.IsNullOrEmpty(desc.ParameterAssemblyFullName))
{
string paramName =
- string.Format(CultureInfo.InvariantCulture, "descriptions[{0}].AssemblyFullName", descIndex);
+ string.Create(CultureInfo.InvariantCulture, $"descriptions[{descIndex}].AssemblyFullName");
throw PSTraceSource.NewArgumentException(paramName, ConsoleHostUserInterfaceStrings.NullOrEmptyErrorTemplate, paramName);
}
@@ -493,7 +493,7 @@ namespace Microsoft.PowerShell
private string PromptCommandMode(string input, FieldDescription desc, out bool inputDone)
{
Dbg.Assert(input != null && input.StartsWith(PromptCommandPrefix, StringComparison.OrdinalIgnoreCase),
- string.Format(CultureInfo.InvariantCulture, "input should start with {0}", PromptCommandPrefix));
+ string.Create(CultureInfo.InvariantCulture, $"input should start with {PromptCommandPrefix}"));
Dbg.Assert(desc != null, "desc should never be null when PromptCommandMode is called");
string command = input.Substring(1);
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs
index fa470b245a..7e3dcfd70e 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs
@@ -426,7 +426,7 @@ namespace Microsoft.PowerShell
WriteLineToConsole(
WrapToCurrentWindowWidth(
- string.Format(CultureInfo.InvariantCulture, "{0} - {1}", s, choices[i].HelpMessage)));
+ string.Create(CultureInfo.InvariantCulture, $"{s} - {choices[i].HelpMessage}")));
}
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/UpdatesNotification.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/UpdatesNotification.cs
index 455efe84d1..28cd31473d 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/UpdatesNotification.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/UpdatesNotification.cs
@@ -353,7 +353,7 @@ namespace Microsoft.PowerShell
using var client = new HttpClient();
- string userAgent = string.Format(CultureInfo.InvariantCulture, "PowerShell {0}", PSVersionInfo.GitCommitId);
+ string userAgent = string.Create(CultureInfo.InvariantCulture, $"PowerShell {PSVersionInfo.GitCommitId}");
client.DefaultRequestHeaders.Add("User-Agent", userAgent);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));