From 74667fed8c5d13952e44e6c49231248f971fd373 Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Wed, 18 Jan 2023 11:36:59 +0100
Subject: [PATCH 1/7] 15 files
---
.../CimNewCimInstance.cs | 2 +-
.../CimRegisterCimIndication.cs | 8 ++++----
.../utility/FormatAndOutput/format-hex/Format-Hex.cs | 2 +-
.../utility/WebCmdlet/Common/ContentHelper.Common.cs | 2 +-
.../utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs | 2 +-
.../commands/utility/XmlCommands.cs | 2 +-
.../host/msh/ConsoleHost.cs | 6 +++---
.../host/msh/ConsoleHostRawUserInterface.cs | 7 +++----
.../host/msh/ConsoleHostUserInterfaceSecurity.cs | 2 +-
src/Microsoft.PowerShell.ScheduledJob/ScheduledJobWTS.cs | 8 +-------
.../security/CertificateProvider.cs | 8 ++++----
.../security/SecureStringCommands.cs | 5 +----
src/Microsoft.WSMan.Management/CredSSP.cs | 6 ++----
.../engine/ComInterop/ComTypeEnumDesc.cs | 2 +-
.../engine/ComInterop/DispCallable.cs | 2 +-
15 files changed, 26 insertions(+), 38 deletions(-)
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimNewCimInstance.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimNewCimInstance.cs
index 176cb1828e2..03f28fb64bc 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimNewCimInstance.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimNewCimInstance.cs
@@ -293,7 +293,7 @@ private CimInstance CreateCimInstance(
object propertyValue = GetBaseObject(enumerator.Value);
- DebugHelper.WriteLog("Create and add new property to ciminstance: name = {0}; value = {1}; flags = {2}", 5, propertyName, propertyValue, flag);
+ DebugHelper.WriteLog($"Create and add new property to ciminstance: name = {propertyName}; value = {propertyValue}; flags = {flag}", 5);
PSReference cimReference = propertyValue as PSReference;
if (cimReference != null)
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
index c08fa0c44ea..a50e2387fb7 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
@@ -125,7 +125,7 @@ public void RegisterCimIndication(
string queryExpression,
uint operationTimeout)
{
- DebugHelper.WriteLogEx("queryDialect = '{0}'; queryExpression = '{1}'", 0, queryDialect, queryExpression);
+ DebugHelper.WriteLogEx($"queryDialect = '{queryDialect}'; queryExpression = '{queryExpression}'", 0);
this.TargetComputerName = computerName;
CimSessionProxy proxy = CreateSessionProxy(computerName, operationTimeout);
proxy.SubscribeAsync(nameSpace, queryDialect, queryExpression);
@@ -148,7 +148,7 @@ public void RegisterCimIndication(
string queryExpression,
uint operationTimeout)
{
- DebugHelper.WriteLogEx("queryDialect = '{0}'; queryExpression = '{1}'", 0, queryDialect, queryExpression);
+ DebugHelper.WriteLogEx($"queryDialect = '{queryDialect}'; queryExpression = '{queryExpression}'", 0);
ArgumentNullException.ThrowIfNull(cimSession, string.Format(CultureInfo.CurrentUICulture, CimCmdletStrings.NullArgument, nameof(cimSession)));
@@ -188,7 +188,7 @@ protected override void SubscribeToCimSessionProxyEvent(CimSessionProxy proxy)
/// Event argument.
private void CimIndicationHandler(object cimSession, CmdletActionEventArgs actionArgs)
{
- DebugHelper.WriteLogEx("action is {0}. Disposed {1}", 0, actionArgs.Action, this.Disposed);
+ DebugHelper.WriteLogEx($"action is {actionArgs.Action}. Disposed {this.Disposed}", 0);
if (this.Disposed)
{
@@ -216,7 +216,7 @@ private void CimIndicationHandler(object cimSession, CmdletActionEventArgs actio
temp(this, new CimSubscriptionExceptionEventArgs(this.Exception));
}
- DebugHelper.WriteLog("Got an exception: {0}", 2, Exception);
+ DebugHelper.WriteLog($"Got an exception: {Exception}", 2);
}
CimWriteResultObject cimWriteResultObject = actionArgs.Action as CimWriteResultObject;
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 de73b2155a6..495f8431b8e 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 @@ private void ProcessString(string originalString)
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.Format($"{inputType.Name} ({inputType.FullName}) <{_idGenerator.Next():X8}>");
private void FlushInputBuffer()
{
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 bf4693c1e3e..d6269d16486 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 @@ internal static StringBuilder GetRawContentHeader(HttpResponseMessage response)
{
int statusCode = WebResponseHelper.GetStatusCode(response);
string statusDescription = WebResponseHelper.GetStatusDescription(response);
- raw.AppendFormat("{0} {1} {2}", protocol, statusCode, statusDescription);
+ raw.AppendFormat($"{protocol} {statusCode} {statusDescription}");
raw.AppendLine();
}
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 73eb34013a5..212617b71a9 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 @@ private static string FormatDictionary(IDictionary content)
encodedValue = WebUtility.UrlEncode(value.ToString());
}
- bodyBuilder.AppendFormat("{0}={1}", encodedKey, encodedValue);
+ bodyBuilder.AppendFormat($"{encodedKey}={encodedValue}");
}
return bodyBuilder.ToString();
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs
index f39242e1010..411c93e9192 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 @@ protected override void BeginProcessing()
}
else
{
- WriteObject(string.Format(CultureInfo.InvariantCulture, "", Encoding.UTF8.WebName));
+ WriteObject(string.Format(CultureInfo.InvariantCulture, $""));
WriteObject("");
}
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
index e2b7bd7b8ba..5ead5fc4c97 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
@@ -1444,7 +1444,7 @@ private uint Run(CommandLineParameterParser cpp, bool isPrestartWarned)
exitCode = ExitCodeSuccess;
if (!string.IsNullOrEmpty(cpp.InitialCommand) && isPrestartWarned)
{
- s_tracer.TraceError("Start up warnings made command \"{0}\" not executed", cpp.InitialCommand);
+ s_tracer.TraceError($"Start up warnings made command \"{cpp.InitialCommand}\" not executed");
string msg = StringUtil.Format(ConsoleHostStrings.InitialCommandNotExecuted, cpp.InitialCommand);
ui.WriteErrorLine(msg);
exitCode = ExitCodeInitFailure;
@@ -1566,7 +1566,7 @@ private Exception InitializeRunspaceHelper(string command, Executor exec, Execut
Dbg.Assert(!string.IsNullOrEmpty(command), "command should have a value");
Dbg.Assert(exec != null, "non-null Executor instance needed");
- s_runspaceInitTracer.WriteLine("running command {0}", command);
+ s_runspaceInitTracer.WriteLine($"running command {command}");
Exception e = null;
@@ -1911,7 +1911,7 @@ private void DoRunspaceInitialization(RunspaceCreationEventArgs args)
{
string filePath = s_cpp.File;
- s_tracer.WriteLine("running -file '{0}'", filePath);
+ s_tracer.WriteLine($"running -file '{filePath}'");
Pipeline tempPipeline = exec.CreatePipeline();
Command c;
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
index f5937d21e0f..6670eb44b5a 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
@@ -639,8 +639,7 @@ public override
{
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.Format(CultureInfo.InvariantCulture, $"ReadConsoleInput returns {actualNumberOfInput} number of input event records"));
if (actualNumberOfInput == 1)
{
if (((ConsoleControl.InputRecordEventTypes)inputRecords[0].EventType) ==
@@ -1532,7 +1531,7 @@ internal struct COORD
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "{0},{1}", X, Y);
+ return string.Format(CultureInfo.InvariantCulture, $"{X},{Y}");
}
}
@@ -1548,7 +1547,7 @@ internal struct SMALL_RECT
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", Left, Top, Right, Bottom);
+ return string.Format(CultureInfo.InvariantCulture, $"{Left},{Top},{Right},{Bottom}");
}
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
index 1e934553f18..691ed5a8291 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs
@@ -115,7 +115,7 @@ public override PSCredential PromptForCredential(
if (!string.IsNullOrEmpty(targetName))
{
- userName = StringUtil.Format("{0}\\{1}", targetName, userName);
+ userName = StringUtil.Format($"{targetName}\\{userName}");
}
cred = new PSCredential(userName, password);
diff --git a/src/Microsoft.PowerShell.ScheduledJob/ScheduledJobWTS.cs b/src/Microsoft.PowerShell.ScheduledJob/ScheduledJobWTS.cs
index a8d76ef7da8..d4e4d6efc96 100644
--- a/src/Microsoft.PowerShell.ScheduledJob/ScheduledJobWTS.cs
+++ b/src/Microsoft.PowerShell.ScheduledJob/ScheduledJobWTS.cs
@@ -797,13 +797,7 @@ private TimeSpan ParseWTSTime(string wtsTime)
/// WTS time string.
internal static string ConvertTimeSpanToWTSString(TimeSpan time)
{
- return string.Format(
- CultureInfo.InvariantCulture,
- "P{0}DT{1}H{2}M{3}S",
- time.Days,
- time.Hours,
- time.Minutes,
- time.Seconds);
+ return string.Format(CultureInfo.InvariantCulture, $"P{time.Days}DT{time.Hours}H{time.Minutes}M{time.Seconds}S");
}
///
diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
index 7644f3de620..c1756a96082 100644
--- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
+++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
@@ -1197,7 +1197,7 @@ protected override bool ItemExists(string path)
result = (bool)item;
}
- s_tracer.WriteLine("result = {0}", result);
+ s_tracer.WriteLine($"result = {result}");
return result;
}
@@ -1345,7 +1345,7 @@ private void AttemptToImportPkiModule()
typeof(Microsoft.PowerShell.Commands.ImportModuleCommand));
Runspaces.Command importModuleCommand = new(commandInfo);
- s_tracer.WriteLine("Attempting to load module: {0}", moduleName);
+ s_tracer.WriteLine($"Attempting to load module: {moduleName}");
try
{
@@ -1440,7 +1440,7 @@ private static string EnsureDriveIsRooted(string path)
result = StringLiterals.DefaultPathSeparator + path;
}
- s_tracer.WriteLine("result = {0}", result);
+ s_tracer.WriteLine($"result = {result}");
return result;
}
@@ -2236,7 +2236,7 @@ protected override bool IsItemContainer(string path)
GetItemAtPath(path, true, out isContainer);
}
- s_tracer.WriteLine("result = {0}", isContainer);
+ s_tracer.WriteLine($"result = {isContainer}");
return isContainer;
}
diff --git a/src/Microsoft.PowerShell.Security/security/SecureStringCommands.cs b/src/Microsoft.PowerShell.Security/security/SecureStringCommands.cs
index c727476c0a3..098eb6d4451 100644
--- a/src/Microsoft.PowerShell.Security/security/SecureStringCommands.cs
+++ b/src/Microsoft.PowerShell.Security/security/SecureStringCommands.cs
@@ -193,10 +193,7 @@ protected override void ProcessRecord()
// Initialization Vector, Encrypted Data
string dataPackage = string.Format(
System.Globalization.CultureInfo.InvariantCulture,
- "{0}|{1}|{2}",
- 2,
- encryptionResult.IV,
- encryptionResult.EncryptedData);
+ $"{2}|{encryptionResult.IV}|{encryptionResult.EncryptedData}");
// encode the package, and output it.
// We also include a recognizable prefix so that
diff --git a/src/Microsoft.WSMan.Management/CredSSP.cs b/src/Microsoft.WSMan.Management/CredSSP.cs
index 2470a6fc3c4..127820c2c58 100644
--- a/src/Microsoft.WSMan.Management/CredSSP.cs
+++ b/src/Microsoft.WSMan.Management/CredSSP.cs
@@ -201,8 +201,7 @@ private void DisableServerSideSettings()
}
string inputXml = string.Format(CultureInfo.InvariantCulture,
- @"false",
- helper.Service_CredSSP_XMLNmsp);
+ $@"false");
m_SessionObj.Put(helper.Service_CredSSP_Uri, inputXml, 0);
}
@@ -593,8 +592,7 @@ private void EnableServerSideSettings()
{
XmlDocument xmldoc = new XmlDocument();
string newxmlcontent = string.Format(CultureInfo.InvariantCulture,
- @"true",
- helper.Service_CredSSP_XMLNmsp);
+ $@"true");
// push the xml string with credssp enabled
xmldoc.LoadXml(m_SessionObj.Put(helper.Service_CredSSP_Uri, newxmlcontent, 0));
WriteObject(xmldoc.FirstChild);
diff --git a/src/System.Management.Automation/engine/ComInterop/ComTypeEnumDesc.cs b/src/System.Management.Automation/engine/ComInterop/ComTypeEnumDesc.cs
index 1f59dc475e5..8b4fd09ac91 100644
--- a/src/System.Management.Automation/engine/ComInterop/ComTypeEnumDesc.cs
+++ b/src/System.Management.Automation/engine/ComInterop/ComTypeEnumDesc.cs
@@ -17,7 +17,7 @@ internal sealed class ComTypeEnumDesc : ComTypeDesc, IDynamicMetaObjectProvider
public override string ToString()
{
- return string.Format(CultureInfo.CurrentCulture, "", TypeName);
+ return string.Format(CultureInfo.CurrentCulture, $"");
}
internal ComTypeEnumDesc(ComTypes.ITypeInfo typeInfo, ComTypeLibDesc typeLibDesc) : base(typeInfo, typeLibDesc)
diff --git a/src/System.Management.Automation/engine/ComInterop/DispCallable.cs b/src/System.Management.Automation/engine/ComInterop/DispCallable.cs
index df0f54009ac..cd2f7e9920f 100644
--- a/src/System.Management.Automation/engine/ComInterop/DispCallable.cs
+++ b/src/System.Management.Automation/engine/ComInterop/DispCallable.cs
@@ -21,7 +21,7 @@ internal DispCallable(IDispatchComObject dispatch, string memberName, int dispId
public override string ToString()
{
- return string.Format(CultureInfo.CurrentCulture, "", MemberName);
+ return string.Format(CultureInfo.CurrentCulture, $"");
}
public IDispatchComObject DispatchComObject { get; }
From 9dbf28270fb2fff893274ea928933fbea0415842 Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Wed, 18 Jan 2023 11:49:48 +0100
Subject: [PATCH 2/7] 11 files
---
src/System.Management.Automation/engine/hostifaces/PSTask.cs | 2 +-
.../engine/interpreter/BranchLabel.cs | 2 +-
.../engine/interpreter/InstructionList.cs | 2 +-
src/System.Management.Automation/engine/parser/Compiler.cs | 2 +-
src/System.Management.Automation/engine/parser/Parser.cs | 2 +-
src/System.Management.Automation/engine/parser/Position.cs | 4 +---
.../engine/remoting/client/Job.cs | 3 +--
.../engine/remoting/server/serverremotesession.cs | 2 +-
.../engine/runtime/ScriptBlockToPowerShell.cs | 2 +-
test/perf/benchmarks/Program.cs | 2 +-
test/tools/TestExe/TestExe.cs | 2 +-
11 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/src/System.Management.Automation/engine/hostifaces/PSTask.cs b/src/System.Management.Automation/engine/hostifaces/PSTask.cs
index fb492706ad1..8edb42df85b 100644
--- a/src/System.Management.Automation/engine/hostifaces/PSTask.cs
+++ b/src/System.Management.Automation/engine/hostifaces/PSTask.cs
@@ -912,7 +912,7 @@ private void CheckForComplete()
private Runspace GetRunspace(int taskId)
{
- var runspaceName = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", PSTask.RunspaceName, taskId);
+ var runspaceName = string.Format(CultureInfo.InvariantCulture, $"{PSTask.RunspaceName}:{taskId}");
if (_useRunspacePool && _runspacePool.TryDequeue(out Runspace runspace))
{
diff --git a/src/System.Management.Automation/engine/interpreter/BranchLabel.cs b/src/System.Management.Automation/engine/interpreter/BranchLabel.cs
index 1bae16783a9..bcebdd3ffe0 100644
--- a/src/System.Management.Automation/engine/interpreter/BranchLabel.cs
+++ b/src/System.Management.Automation/engine/interpreter/BranchLabel.cs
@@ -34,7 +34,7 @@ public RuntimeLabel(int index, int continuationStackDepth, int stackDepth)
public override string ToString()
{
- return string.Format(CultureInfo.InvariantCulture, "->{0} C({1}) S({2})", Index, ContinuationStackDepth, StackDepth);
+ return string.Format(CultureInfo.InvariantCulture, $"->{Index} C({ContinuationStackDepth}) S({StackDepth})");
}
}
diff --git a/src/System.Management.Automation/engine/interpreter/InstructionList.cs b/src/System.Management.Automation/engine/interpreter/InstructionList.cs
index 93946bfd2c3..cb70014a7b5 100644
--- a/src/System.Management.Automation/engine/interpreter/InstructionList.cs
+++ b/src/System.Management.Automation/engine/interpreter/InstructionList.cs
@@ -283,7 +283,7 @@ static InstructionList() {
}
PerfTrack.DumpHistogram(referenced);
- Console.WriteLine("-- Total referenced: {0}", total);
+ Console.WriteLine($"-- Total referenced: {total}");
Console.WriteLine("-----");
});
}
diff --git a/src/System.Management.Automation/engine/parser/Compiler.cs b/src/System.Management.Automation/engine/parser/Compiler.cs
index 676ed06fcd0..06f50ca2848 100644
--- a/src/System.Management.Automation/engine/parser/Compiler.cs
+++ b/src/System.Management.Automation/engine/parser/Compiler.cs
@@ -1149,7 +1149,7 @@ private Expression UpdatePosition(Ast ast)
internal ParameterExpression NewTemp(Type type, string name)
{
- return Expression.Variable(type, string.Format(CultureInfo.InvariantCulture, "{0}{1}", name, _tempCounter++));
+ return Expression.Variable(type, string.Format(CultureInfo.InvariantCulture, $"{name}{_tempCounter++}"));
}
internal static Type GetTypeConstraintForMethodResolution(ExpressionAst expr)
diff --git a/src/System.Management.Automation/engine/parser/Parser.cs b/src/System.Management.Automation/engine/parser/Parser.cs
index c0bdd25740a..8661f52439e 100644
--- a/src/System.Management.Automation/engine/parser/Parser.cs
+++ b/src/System.Management.Automation/engine/parser/Parser.cs
@@ -8044,7 +8044,7 @@ private static void AssertErrorIdCorrespondsToMsgString(string errorId, string e
}
}
- Diagnostics.Assert(msgCorrespondsToString, string.Format("Parser error ID \"{0}\" must correspond to the error message \"{1}\"", errorId, errorMsg));
+ Diagnostics.Assert(msgCorrespondsToString, string.Format($"Parser error ID \"{errorId}\" must correspond to the error message \"{errorMsg}\""));
}
private static object[] arrayOfOneArg
diff --git a/src/System.Management.Automation/engine/parser/Position.cs b/src/System.Management.Automation/engine/parser/Position.cs
index 3c4281e5446..f3af554e1f4 100644
--- a/src/System.Management.Automation/engine/parser/Position.cs
+++ b/src/System.Management.Automation/engine/parser/Position.cs
@@ -766,9 +766,7 @@ public string Text
_endPosition.ColumnNumber - _startPosition.ColumnNumber);
}
- return string.Format(CultureInfo.InvariantCulture, "{0}...{1}",
- _startPosition.Line.Substring(_startPosition.ColumnNumber),
- _endPosition.Line.Substring(0, _endPosition.ColumnNumber));
+ return string.Format(CultureInfo.InvariantCulture, $"{_startPosition.Line.Substring(_startPosition.ColumnNumber)}...{_endPosition.Line.Substring(0, _endPosition.ColumnNumber)}");
}
else
{
diff --git a/src/System.Management.Automation/engine/remoting/client/Job.cs b/src/System.Management.Automation/engine/remoting/client/Job.cs
index 74bd83c1faf..3bd7920b855 100644
--- a/src/System.Management.Automation/engine/remoting/client/Job.cs
+++ b/src/System.Management.Automation/engine/remoting/client/Job.cs
@@ -3307,8 +3307,7 @@ protected void ProcessJobFailure(ExecutionCmdletHelper helper, out Exception fai
errorId = "InvalidSessionState";
if (!string.IsNullOrEmpty(failureException.Source))
{
- errorId = string.Format(System.Globalization.CultureInfo.InvariantCulture,
- "{0},{1}", errorId, failureException.Source);
+ errorId = string.Format(System.Globalization.CultureInfo.InvariantCulture, $"{errorId},{failureException.Source}");
}
}
diff --git a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs
index 7f0e5636a4e..005b769ed23 100644
--- a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs
+++ b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs
@@ -207,7 +207,7 @@ internal static ServerRemoteSession CreateServerRemoteSession(
(senderInfo != null) && (senderInfo.UserInfo != null),
"senderInfo and userInfo cannot be null.");
- s_trace.WriteLine("Finding InitialSessionState provider for id : {0}", configurationProviderId);
+ s_trace.WriteLine($"Finding InitialSessionState provider for id : {configurationProviderId}");
if (string.IsNullOrEmpty(configurationProviderId))
{
diff --git a/src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs b/src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs
index a3185149ecd..719218f9eab 100644
--- a/src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs
+++ b/src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs
@@ -946,7 +946,7 @@ private void AddParameter(CommandParameterAst commandParameterAst, bool isTruste
// first character in parameter name must be a dash
_powershell.AddParameter(
- string.Format(CultureInfo.InvariantCulture, "-{0}{1}", commandParameterAst.ParameterName, nameSuffix),
+ string.Format(CultureInfo.InvariantCulture, $"-{commandParameterAst.ParameterName}{nameSuffix}"),
argument);
}
}
diff --git a/test/perf/benchmarks/Program.cs b/test/perf/benchmarks/Program.cs
index 53f9a3ce95b..b5ba56c9d09 100644
--- a/test/perf/benchmarks/Program.cs
+++ b/test/perf/benchmarks/Program.cs
@@ -34,7 +34,7 @@ public static int Main(string[] args)
}
catch (ArgumentException e)
{
- Console.WriteLine("ArgumentException: {0}", e.Message);
+ Console.WriteLine($"ArgumentException: {e.Message}");
return 1;
}
diff --git a/test/tools/TestExe/TestExe.cs b/test/tools/TestExe/TestExe.cs
index ab8f76d5425..a376880fc17 100644
--- a/test/tools/TestExe/TestExe.cs
+++ b/test/tools/TestExe/TestExe.cs
@@ -59,7 +59,7 @@ private static void EchoArgs(string[] args)
{
for (int i = 1; i < args.Length; i++)
{
- Console.WriteLine("Arg {0} is <{1}>", i - 1, args[i]);
+ Console.WriteLine($"Arg {i - 1} is <{args[i]}>");
}
}
From 2775d5f91b3de9af4f6521456112234bf12ee977 Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Wed, 18 Jan 2023 11:58:36 +0100
Subject: [PATCH 3/7] 6 files
---
.../ManagementList/Common/WpfHelp.cs | 8 ++------
.../ManagementList/FilterCore/ValidatingSelectorValue.cs | 2 +-
.../ManagementList/FilterCore/ValidatingValueBase.cs | 2 +-
.../ManagementList/FilterProviders/SearchTextParser.cs | 4 ++--
.../ImportCounterCommand.cs | 2 +-
.../cimSupport/other/ciminstancetypeadapter.cs | 7 ++-----
6 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/src/Microsoft.Management.UI.Internal/ManagementList/Common/WpfHelp.cs b/src/Microsoft.Management.UI.Internal/ManagementList/Common/WpfHelp.cs
index 4bc9ebef28d..2f6db8297df 100644
--- a/src/Microsoft.Management.UI.Internal/ManagementList/Common/WpfHelp.cs
+++ b/src/Microsoft.Management.UI.Internal/ManagementList/Common/WpfHelp.cs
@@ -463,9 +463,7 @@ private static void HandleWrongTemplatePartType(string name)
{
throw new ApplicationException(string.Format(
CultureInfo.CurrentCulture,
- "A template part with the name of '{0}' is not of type {1}.",
- name,
- typeof(T).Name));
+ $"A template part with the name of '{name}' is not of type {typeof(T).Name}."));
}
///
@@ -477,9 +475,7 @@ public static void HandleMissingTemplatePart(string name)
{
throw new ApplicationException(string.Format(
CultureInfo.CurrentCulture,
- "A template part with the name of '{0}' and type of {1} was not found.",
- name,
- typeof(T).Name));
+ $"A template part with the name of '{name}' and type of {typeof(T).Name} was not found."));
}
#endregion TemplateChild
diff --git a/src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/ValidatingSelectorValue.cs b/src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/ValidatingSelectorValue.cs
index e86f2020ecc..94efe5f5ba2 100644
--- a/src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/ValidatingSelectorValue.cs
+++ b/src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/ValidatingSelectorValue.cs
@@ -188,7 +188,7 @@ protected override DataErrorInfoValidationResult Validate(string columnName)
{
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.Format(CultureInfo.CurrentCulture, $"{columnName} is not a valid column name."), "columnName");
}
if (!this.IsIndexWithinBounds(this.SelectedIndex))
diff --git a/src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/ValidatingValueBase.cs b/src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/ValidatingValueBase.cs
index f33862846a9..526932bc8e7 100644
--- a/src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/ValidatingValueBase.cs
+++ b/src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/ValidatingValueBase.cs
@@ -218,7 +218,7 @@ internal DataErrorInfoValidationResult EvaluateValidationRules(object value, Sys
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.Format(CultureInfo.CurrentCulture, $"DataErrorInfoValidationResult not returned by ValidationRule: {rule.ToString()}"));
}
if (!result.IsValid)
diff --git a/src/Microsoft.Management.UI.Internal/ManagementList/FilterProviders/SearchTextParser.cs b/src/Microsoft.Management.UI.Internal/ManagementList/FilterProviders/SearchTextParser.cs
index c64683c7301..5552628e23e 100644
--- a/src/Microsoft.Management.UI.Internal/ManagementList/FilterProviders/SearchTextParser.cs
+++ b/src/Microsoft.Management.UI.Internal/ManagementList/FilterProviders/SearchTextParser.cs
@@ -121,7 +121,7 @@ protected virtual string GetPattern()
patterns.Add(rule.Pattern);
}
- patterns.Add(string.Format(CultureInfo.InvariantCulture, "(?<{0}>){1}", FullTextRuleGroupName, ValuePattern));
+ patterns.Add(string.Format(CultureInfo.InvariantCulture, $"(?<{FullTextRuleGroupName}>){ValuePattern}"));
return string.Join("|", patterns.ToArray());
}
@@ -199,7 +199,7 @@ public SearchableRule(string uniqueId, SelectorFilterRule selectorFilterRule, Te
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.Format(CultureInfo.InvariantCulture, $"(?<{uniqueId}>){Regex.Escape(selectorFilterRule.DisplayName)}\\s*:\\s*{SearchTextParser.ValuePattern}");
}
///
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs
index d571df34084..e6768878cda 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/ImportCounterCommand.cs
@@ -240,7 +240,7 @@ protected override void EndProcessing()
break;
default:
- Debug.Assert(false, string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", ParameterSetName));
+ Debug.Assert(false, string.Format(CultureInfo.InvariantCulture, $"Invalid parameter set name: {ParameterSetName}"));
break;
}
diff --git a/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs b/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs
index 6b1b85c125d..528bef4b73f 100644
--- a/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs
+++ b/src/System.Management.Automation/cimSupport/other/ciminstancetypeadapter.cs
@@ -239,15 +239,12 @@ private static void AddTypeNameHierarchy(IList typeNamesWithNamespace, I
if (!string.IsNullOrEmpty(namespaceName))
{
string fullTypeName = string.Format(CultureInfo.InvariantCulture,
- "Microsoft.Management.Infrastructure.CimInstance#{0}/{1}",
- namespaceName,
- className);
+ $"Microsoft.Management.Infrastructure.CimInstance#{namespaceName}/{className}");
typeNamesWithNamespace.Add(fullTypeName);
}
typeNamesWithoutNamespace.Add(string.Format(CultureInfo.InvariantCulture,
- "Microsoft.Management.Infrastructure.CimInstance#{0}",
- className));
+ $"Microsoft.Management.Infrastructure.CimInstance#{className}"));
}
private static List GetInheritanceChain(CimInstance cimInstance)
From 5884f7ea71090b70a214ed6f7c3a5db3b5de4c10 Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Wed, 18 Jan 2023 15:22:57 +0100
Subject: [PATCH 4/7] 5 files
---
.../CimSetCimInstance.cs | 8 ++++----
.../CimWriteProgress.cs | 8 ++------
.../CmdletOperation.cs | 2 +-
.../NewCimSessionCommand.cs | 6 +++---
.../RegisterCimIndicationCommand.cs | 2 +-
5 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs
index 91cf332bde9..c018ad7849e 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs
@@ -191,7 +191,7 @@ private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, re
{
object value = GetBaseObject(enumerator.Value);
string key = enumerator.Key.ToString();
- DebugHelper.WriteLog("Input property name '{0}' with value '{1}'", 1, key, value);
+ DebugHelper.WriteLog($"Input property name '{key}' with value '{value}'", 1);
try
{
@@ -208,7 +208,7 @@ private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, re
}
// allow modify the key property value as long as it is not readonly,
// then the modified ciminstance is stand for a different CimInstance
- DebugHelper.WriteLog("Set property name '{0}' has old value '{1}'", 4, key, property.Value);
+ DebugHelper.WriteLog($"Set property name '{key}' has old value '{property.Value}'", 4);
property.Value = value;
}
else // For dynamic instance, it is valid to add a new property
@@ -265,12 +265,12 @@ private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, re
return false;
}
- DebugHelper.WriteLog("Add non-key property name '{0}' with value '{1}'.", 3, key, value);
+ DebugHelper.WriteLog($"Add non-key property name '{key}' with value '{value}'.", 3);
}
}
catch (Exception e)
{
- DebugHelper.WriteLog("Exception {0}", 4, e);
+ DebugHelper.WriteLog($"Exception {e}", 4);
exception = e;
return false;
}
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs
index b99407ccc81..92df37753c7 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs
@@ -68,12 +68,8 @@ public CimWriteProgress(
public override void Execute(CmdletOperationBase cmdlet)
{
DebugHelper.WriteLog(
- "...Activity {0}: id={1}, remain seconds ={2}, percentage completed = {3}",
- 4,
- this.Activity,
- this.ActivityID,
- this.SecondsRemaining,
- this.PercentageCompleted);
+ $"...Activity {this.Activity}: id={this.ActivityID}, remain seconds ={this.SecondsRemaining}, percentage completed = {this.PercentageCompleted}",
+ 4);
ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
ProgressRecord record = new(
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
index 03db6967aef..080d46b5875 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
@@ -387,7 +387,7 @@ public override void WriteObject(object sendToPipeline, XOperationContextBase co
else
{
// NOTES: May need to output for warning message/verbose message
- DebugHelper.WriteLog("Ignore other type object {0}", 1, sendToPipeline);
+ DebugHelper.WriteLog($"Ignore other type object {sendToPipeline}", 1);
}
}
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs
index f048a22a9f6..05ce6150002 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs
@@ -299,16 +299,16 @@ internal void BuildSessionOptions(out CimSessionOptions outputOptions, out CimCr
return;
}
- DebugHelper.WriteLog("Credentials: {0}", 1, credentials);
+ DebugHelper.WriteLog($"Credentials: {credentials}", 1);
outputCredential = credentials;
if (options != null)
{
- DebugHelper.WriteLog("Add credentials to option: {0}", 1, options);
+ DebugHelper.WriteLog($"Add credentials to option: {options}", 1);
options.AddDestinationCredentials(credentials);
}
}
- DebugHelper.WriteLogEx("Set outputOptions: {0}", 1, outputOptions);
+ DebugHelper.WriteLogEx($"Set outputOptions: {outputOptions}", 1);
outputOptions = options;
}
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs
index d5dc44a31d4..49dcae0f7d9 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs
@@ -205,7 +205,7 @@ protected override object GetSourceObject()
case CimBaseCommand.ClassNameComputerSet:
// validate the classname
this.CheckArgument();
- tempQueryExpression = string.Format(CultureInfo.CurrentCulture, "Select * from {0}", this.ClassName);
+ tempQueryExpression = string.Format(CultureInfo.CurrentCulture, $"Select * from {this.ClassName}");
break;
}
From b022a388f85c42ab3e3fc42c8652609e0f8fdf50 Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Wed, 18 Jan 2023 15:30:11 +0100
Subject: [PATCH 5/7] 8 files
---
.../ShowCommand/ViewModel/CommandViewModel.cs | 2 +-
.../ShowCommand/ViewModel/ParameterSetViewModel.cs | 4 ++--
.../ShowCommand/ViewModel/ParameterViewModel.cs | 2 +-
.../GetCounterCommand.cs | 2 +-
.../commands/management/GetComputerInfoCommand.cs | 2 +-
.../commands/utility/AddType.cs | 2 +-
.../commands/utility/CsvCommands.cs | 2 +-
.../commands/utility/Get-PSBreakpoint.cs | 2 +-
8 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/CommandViewModel.cs b/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/CommandViewModel.cs
index 367b5d08131..711065c093c 100644
--- a/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/CommandViewModel.cs
+++ b/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/CommandViewModel.cs
@@ -431,7 +431,7 @@ public string GetScript()
if (commandName.Contains(' '))
{
- builder.AppendFormat("& \"{0}\"", commandName);
+ builder.AppendFormat($"& \"{commandName}\"");
}
else
{
diff --git a/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ParameterSetViewModel.cs b/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ParameterSetViewModel.cs
index 9d59ca3dc1d..95f2bd0489b 100644
--- a/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ParameterSetViewModel.cs
+++ b/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ParameterSetViewModel.cs
@@ -138,7 +138,7 @@ public string GetScript()
{
if (((bool?)parameter.Value) == true)
{
- builder.AppendFormat("-{0} ", parameter.Name);
+ builder.AppendFormat($"-{parameter.Name} ");
}
continue;
@@ -166,7 +166,7 @@ public string GetScript()
parameterValueString = ParameterSetViewModel.GetDelimitedParameter(parameterValueString, "(", ")");
}
- builder.AppendFormat("-{0} {1} ", parameter.Name, parameterValueString);
+ builder.AppendFormat($"-{parameter.Name} {parameterValueString} ");
}
return builder.ToString().Trim();
diff --git a/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ParameterViewModel.cs b/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ParameterViewModel.cs
index 32eb8271938..0e45f720817 100644
--- a/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ParameterViewModel.cs
+++ b/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ParameterViewModel.cs
@@ -159,7 +159,7 @@ public string NameCheckLabel
string returnValue = this.Parameter.Name;
if (this.Parameter.IsMandatory)
{
- returnValue = string.Format(CultureInfo.CurrentUICulture, "{0}{1}", returnValue, ShowCommandResources.MandatoryLabelSegment);
+ returnValue = string.Format(CultureInfo.CurrentUICulture, $"{returnValue}{ShowCommandResources.MandatoryLabelSegment}");
}
return returnValue;
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
index f04c8ceff0f..6ab1c6fe167 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetCounterCommand.cs
@@ -248,7 +248,7 @@ protected override void ProcessRecord()
break;
default:
- Debug.Fail(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", ParameterSetName));
+ Debug.Fail(string.Format(CultureInfo.InvariantCulture, $"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 7f69d6defd7..c40658fc769 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 @@ private static string GetHalVersion(CimSession session, string systemDirectory)
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.Format($"SELECT * FROM CIM_DataFile Where Name='{halPath}'");
var instance = session.QueryFirstInstance(query);
if (instance != null)
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs
index bc1d6b0ba4e..3bd5abab1fd 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs
@@ -1030,7 +1030,7 @@ private void SourceCodeProcessing()
syntaxTrees.Add(ParseSourceText(sourceText, parseOptions));
break;
default:
- Diagnostics.Assert(false, "Invalid parameter set: {0}", this.ParameterSetName);
+ Diagnostics.Assert(false, $"Invalid parameter set: {this.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 3557946b24d..eaec8309632 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 @@ internal static string GetTypeString(PSObject source)
temp = temp.Substring(4);
}
- type = string.Format(System.Globalization.CultureInfo.InvariantCulture, "#TYPE {0}", temp);
+ type = string.Format(System.Globalization.CultureInfo.InvariantCulture, $"#TYPE {temp}");
}
return type;
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Get-PSBreakpoint.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Get-PSBreakpoint.cs
index 85bb8fa53b7..3214f8e7077 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Get-PSBreakpoint.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Get-PSBreakpoint.cs
@@ -177,7 +177,7 @@ protected override void ProcessRecord()
}
else
{
- Diagnostics.Assert(false, "Invalid parameter set: {0}", this.ParameterSetName);
+ Diagnostics.Assert(false, $"Invalid parameter set: {this.ParameterSetName}");
}
// Filter by script
From 9e4099cba8a0a0a92639adac54aaca91fedffe6c Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Wed, 18 Jan 2023 15:36:47 +0100
Subject: [PATCH 6/7] 6 files
---
.../host/msh/ConsoleHostUserInterfacePromptForChoice.cs | 4 ++--
.../engine/DataStoreAdapterProvider.cs | 8 ++------
.../engine/ExternalScriptInfo.cs | 4 +---
src/System.Management.Automation/engine/FunctionInfo.cs | 4 +---
.../engine/InternalCommands.cs | 6 +++---
.../engine/ParameterBinderController.cs | 2 +-
6 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs
index 872aaa19a9c..6dc4c4e97bb 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs
@@ -346,7 +346,7 @@ private void WriteChoicePrompt(string[,] hotkeysAndPlainLabels,
}
defaultChoicesBuilder.Append(string.Format(CultureInfo.InvariantCulture,
- "{0}{1}", prepend, defaultStr));
+ $"{prepend}{defaultStr}"));
prepend = ",";
}
@@ -427,7 +427,7 @@ private void ShowChoiceHelp(Collection choices, string[,] hot
WriteLineToConsole(
WrapToCurrentWindowWidth(
- string.Format(CultureInfo.InvariantCulture, "{0} - {1}", s, choices[i].HelpMessage)));
+ string.Format(CultureInfo.InvariantCulture, $"{s} - {choices[i].HelpMessage}")));
}
}
diff --git a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs
index 3ea2fd00fff..0bf4d56bf00 100644
--- a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs
+++ b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs
@@ -59,9 +59,7 @@ static string GetFullName(string name, string psSnapInName, string moduleName)
result =
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
- "{0}\\{1}",
- psSnapInName,
- name);
+ $"{psSnapInName}\\{name}");
}
// After converting core snapins to load as modules, the providers will have Module property populated
@@ -70,9 +68,7 @@ static string GetFullName(string name, string psSnapInName, string moduleName)
result =
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
- "{0}\\{1}",
- moduleName,
- name);
+ $"{moduleName}\\{name}");
}
return result;
diff --git a/src/System.Management.Automation/engine/ExternalScriptInfo.cs b/src/System.Management.Automation/engine/ExternalScriptInfo.cs
index 52713edb874..efcb5844d8e 100644
--- a/src/System.Management.Automation/engine/ExternalScriptInfo.cs
+++ b/src/System.Management.Automation/engine/ExternalScriptInfo.cs
@@ -172,9 +172,7 @@ internal override string Syntax
synopsis.AppendLine(
string.Format(
Globalization.CultureInfo.CurrentCulture,
- "{0} {1}",
- Name,
- parameterSet));
+ $"{Name} {parameterSet}"));
}
return synopsis.ToString();
diff --git a/src/System.Management.Automation/engine/FunctionInfo.cs b/src/System.Management.Automation/engine/FunctionInfo.cs
index 70ab80e8ca4..744050d4ec0 100644
--- a/src/System.Management.Automation/engine/FunctionInfo.cs
+++ b/src/System.Management.Automation/engine/FunctionInfo.cs
@@ -455,9 +455,7 @@ internal override string Syntax
synopsis.AppendLine(
string.Format(
Globalization.CultureInfo.CurrentCulture,
- "{0} {1}",
- Name,
- parameterSet.ToString()));
+ $"{Name} {parameterSet.ToString()}"));
}
return synopsis.ToString();
diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs
index 8ef6976c446..a761c308f25 100644
--- a/src/System.Management.Automation/engine/InternalCommands.cs
+++ b/src/System.Management.Automation/engine/InternalCommands.cs
@@ -701,7 +701,7 @@ private void ProcessPropertyAndMethodParameterSet()
StringBuilder possibleMatches = new StringBuilder();
foreach (PSMemberInfo item in members)
{
- possibleMatches.AppendFormat(CultureInfo.InvariantCulture, " {0}", item.Name);
+ possibleMatches.AppendFormat(CultureInfo.InvariantCulture, $" {item.Name}");
}
WriteError(GenerateNameParameterError("Name", InternalCommandStrings.AmbiguousPropertyOrMethodName,
@@ -1019,7 +1019,7 @@ private void MethodCallWithArguments()
StringBuilder possibleMatches = new StringBuilder();
foreach (PSMemberInfo item in methods)
{
- possibleMatches.AppendFormat(CultureInfo.InvariantCulture, " {0}", item.Name);
+ possibleMatches.AppendFormat(CultureInfo.InvariantCulture, $" {item.Name}");
}
WriteError(GenerateNameParameterError(
@@ -2355,7 +2355,7 @@ private object GetValue(ref bool error)
StringBuilder possibleMatches = new StringBuilder();
foreach (PSMemberInfo item in members)
{
- possibleMatches.AppendFormat(CultureInfo.InvariantCulture, " {0}", item.Name);
+ possibleMatches.AppendFormat(CultureInfo.InvariantCulture, $" {item.Name}");
}
WriteError(
diff --git a/src/System.Management.Automation/engine/ParameterBinderController.cs b/src/System.Management.Automation/engine/ParameterBinderController.cs
index e6a7153a879..0a8971bfc03 100644
--- a/src/System.Management.Automation/engine/ParameterBinderController.cs
+++ b/src/System.Management.Automation/engine/ParameterBinderController.cs
@@ -1029,7 +1029,7 @@ protected void ThrowElaboratedBindingException(ParameterBindingException pbex)
StringBuilder defaultParamsGetBound = new StringBuilder();
foreach (string paramName in BoundDefaultParameters)
{
- defaultParamsGetBound.AppendFormat(CultureInfo.InvariantCulture, " -{0}", paramName);
+ defaultParamsGetBound.AppendFormat(CultureInfo.InvariantCulture, $" -{paramName}");
}
string resourceString = ParameterBinderStrings.DefaultBindingErrorElaborationSingle;
From af514bab4cf60b56cf0ee2f745a8281fcb92d984 Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Wed, 18 Jan 2023 17:46:35 +0100
Subject: [PATCH 7/7] 5 files
---
.../FormatAndOutput/common/DisplayDatabase/FormatTable.cs | 4 ++--
src/System.Management.Automation/help/AliasHelpInfo.cs | 2 +-
.../help/BaseCommandHelpInfo.cs | 2 +-
.../help/CommandHelpProvider.cs | 8 ++++----
.../help/DscResourceHelpProvider.cs | 4 ++--
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/FormatTable.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/FormatTable.cs
index 91d0fabf44c..a182d58d423 100644
--- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/FormatTable.cs
+++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/FormatTable.cs
@@ -98,7 +98,7 @@ protected FormatTableLoadException(SerializationInfo info, StreamingContext cont
_errors = new Collection();
for (int index = 0; index < errorCount; index++)
{
- string key = string.Format(CultureInfo.InvariantCulture, "Error{0}", index);
+ string key = string.Format(CultureInfo.InvariantCulture, $"Error{index}");
_errors.Add(info.GetString(key));
}
}
@@ -127,7 +127,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
for (int index = 0; index < errorCount; index++)
{
- string key = string.Format(CultureInfo.InvariantCulture, "Error{0}", index);
+ string key = string.Format(CultureInfo.InvariantCulture, $"Error{index}");
info.AddValue(key, _errors[index]);
}
}
diff --git a/src/System.Management.Automation/help/AliasHelpInfo.cs b/src/System.Management.Automation/help/AliasHelpInfo.cs
index 8ac441e4e60..9ffc4b4e798 100644
--- a/src/System.Management.Automation/help/AliasHelpInfo.cs
+++ b/src/System.Management.Automation/help/AliasHelpInfo.cs
@@ -41,7 +41,7 @@ private AliasHelpInfo(AliasInfo aliasInfo)
_fullHelpObject.TypeNames.Clear();
_fullHelpObject.TypeNames.Add(string.Format(Globalization.CultureInfo.InvariantCulture,
- "AliasHelpInfo#{0}", Name));
+ $"AliasHelpInfo#{Name}"));
_fullHelpObject.TypeNames.Add("AliasHelpInfo");
_fullHelpObject.TypeNames.Add("HelpInfo");
}
diff --git a/src/System.Management.Automation/help/BaseCommandHelpInfo.cs b/src/System.Management.Automation/help/BaseCommandHelpInfo.cs
index 8a5969e7b35..3c07f75153b 100644
--- a/src/System.Management.Automation/help/BaseCommandHelpInfo.cs
+++ b/src/System.Management.Automation/help/BaseCommandHelpInfo.cs
@@ -215,7 +215,7 @@ internal Uri LookupUriFromCommandInfo()
if (!string.IsNullOrEmpty(moduleName))
{
commandToSearch = string.Format(CultureInfo.InvariantCulture,
- "{0}\\{1}", moduleName, commandName);
+ $"{moduleName}\\{commandName}");
}
ExecutionContext context = LocalPipeline.GetExecutionContextFromTLS();
diff --git a/src/System.Management.Automation/help/CommandHelpProvider.cs b/src/System.Management.Automation/help/CommandHelpProvider.cs
index e32d1c86354..8f01a38b9f2 100644
--- a/src/System.Management.Automation/help/CommandHelpProvider.cs
+++ b/src/System.Management.Automation/help/CommandHelpProvider.cs
@@ -544,7 +544,7 @@ private string GetHelpFile(string helpFile, CmdletInfo cmdletInfo)
// like "get-command -syntax"
if (string.IsNullOrEmpty(location))
{
- s_tracer.WriteLine("Unable to load file {0}", helpFileToLoad);
+ s_tracer.WriteLine($"Unable to load file {helpFileToLoad}");
}
return location;
@@ -706,7 +706,7 @@ private void LoadHelpFile(string helpFile, string helpFileIdentifier)
if (helpItemsNode == null)
{
- s_tracer.WriteLine("Unable to find 'helpItems' element in file {0}", helpFile);
+ s_tracer.WriteLine($"Unable to find 'helpItems' element in file {helpFile}");
return;
}
@@ -951,14 +951,14 @@ private void AddToCommandCache(string mshSnapInId, string cmdletName, MamlComman
// Add snapin qualified type name for this command at the top..
// this will enable customizations of the help object.
helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture,
- "MamlCommandHelpInfo#{0}#{1}", mshSnapInId, cmdletName));
+ $"MamlCommandHelpInfo#{mshSnapInId}#{cmdletName}"));
if (!string.IsNullOrEmpty(mshSnapInId))
{
key = mshSnapInId + "\\" + key;
// Add snapin name to the typenames of this object
helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture,
- "MamlCommandHelpInfo#{0}", mshSnapInId));
+ $"MamlCommandHelpInfo#{mshSnapInId}"));
}
AddCache(key, helpInfo);
diff --git a/src/System.Management.Automation/help/DscResourceHelpProvider.cs b/src/System.Management.Automation/help/DscResourceHelpProvider.cs
index c33a03dc899..1ee26994b8a 100644
--- a/src/System.Management.Automation/help/DscResourceHelpProvider.cs
+++ b/src/System.Management.Automation/help/DscResourceHelpProvider.cs
@@ -279,7 +279,7 @@ private void LoadHelpFile(string helpFile, string helpFileIdentifier, string com
}
if (e != null)
- s_tracer.WriteLine("Error occurred in DscResourceHelpProvider {0}", e.Message);
+ s_tracer.WriteLine($"Error occurred in DscResourceHelpProvider {e.Message}");
if (reportErrors && (e != null))
{
@@ -327,7 +327,7 @@ private void LoadHelpFile(string helpFile, string helpFileIdentifier)
if (helpItemsNode == null)
{
- s_tracer.WriteLine("Unable to find 'helpItems' element in file {0}", helpFile);
+ s_tracer.WriteLine($"Unable to find 'helpItems' element in file {helpFile}");
return;
}