Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)));

Expand Down Expand Up @@ -188,7 +188,7 @@ protected override void SubscribeToCimSessionProxyEvent(CimSessionProxy proxy)
/// <param name="actionArgs">Event argument.</param>
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)
{
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ private static void HandleWrongTemplatePartType<T>(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}."));
}

/// <summary>
Expand All @@ -477,9 +475,7 @@ public static void HandleMissingTemplatePart<T>(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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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}");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public string GetScript()

if (commandName.Contains(' '))
{
builder.AppendFormat("& \"{0}\"", commandName);
builder.AppendFormat($"& \"{commandName}\"");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public string GetScript()
{
if (((bool?)parameter.Value) == true)
{
builder.AppendFormat("-{0} ", parameter.Name);
builder.AppendFormat($"-{parameter.Name} ");
}

continue;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ protected override void BeginProcessing()
}
else
{
WriteObject(string.Format(CultureInfo.InvariantCulture, "<?xml version=\"1.0\" encoding=\"{0}\"?>", Encoding.UTF8.WebName));
WriteObject(string.Format(CultureInfo.InvariantCulture, $"<?xml version=\"1.0\" encoding=\"{Encoding.UTF8.WebName}\"?>"));
WriteObject("<Objects>");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) ==
Expand Down Expand Up @@ -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}");
}
}

Expand All @@ -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}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private void WriteChoicePrompt(string[,] hotkeysAndPlainLabels,
}

defaultChoicesBuilder.Append(string.Format(CultureInfo.InvariantCulture,
"{0}{1}", prepend, defaultStr));
$"{prepend}{defaultStr}"));
prepend = ",";
}

Expand Down Expand Up @@ -427,7 +427,7 @@ private void ShowChoiceHelp(Collection<ChoiceDescription> choices, string[,] hot

WriteLineToConsole(
WrapToCurrentWindowWidth(
string.Format(CultureInfo.InvariantCulture, "{0} - {1}", s, choices[i].HelpMessage)));
string.Format(CultureInfo.InvariantCulture, $"{s} - {choices[i].HelpMessage}")));
}
}

Expand Down
Loading