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 @@ -1092,7 +1092,7 @@ static AnalysisCacheData()
// When multiple copies of pwsh are on the system, they should use their own copy of the cache.
// Append hash of `$PSHOME` to cacheFileName.
string hashString = CRC32Hash.ComputeHash(Utils.DefaultPowerShellAppBase);
cacheFileName = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", cacheFileName, hashString);
cacheFileName = string.Create(CultureInfo.InvariantCulture, $"{cacheFileName}-{hashString}");

if (ExperimentalFeature.EnabledExperimentalFeatureNames.Count > 0)
{
Expand All @@ -1118,7 +1118,7 @@ static AnalysisCacheData()
// Use CRC32 because it's faster.
// It's very unlikely to get collision from hashing the combinations of enabled features names.
hashString = CRC32Hash.ComputeHash(allNames);
cacheFileName = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", cacheFileName, hashString);
cacheFileName = string.Create(CultureInfo.InvariantCulture, $"{cacheFileName}-{hashString}");
}

s_cacheStoreLocation = Path.Combine(Platform.CacheDirectory, cacheFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ private IList<PSModuleInfo> ImportModule_RemotelyViaPsrpSession(
string errorMessageTemplate = string.Format(
CultureInfo.InvariantCulture,
Modules.RemoteDiscoveryRemotePsrpCommandFailed,
string.Format(CultureInfo.InvariantCulture, "Import-Module -Name '{0}'", moduleName));
string.Create(CultureInfo.InvariantCulture, $"Import-Module -Name '{moduleName}'"));
remotelyImportedModules = RemoteDiscoveryHelper.InvokePowerShell(
powerShell,
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4939,7 +4939,7 @@ internal static void SyncCurrentLocationHandler(object sender, LocationChangedEv
using var ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
ps.AddCommand(new CmdletInfo("Invoke-Command", typeof(InvokeCommandCommand)));
ps.AddParameter("Session", compatSession);
ps.AddParameter("ScriptBlock", ScriptBlock.Create(string.Format("Set-Location -Path '{0}'", args.NewPath.Path)));
ps.AddParameter("ScriptBlock", ScriptBlock.Create(string.Create(CultureInfo.InvariantCulture, $"Set-Location -Path '{args.NewPath.Path}'")));
ps.Invoke();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,14 +886,12 @@ private List<string> TryResolveFilePath(string filePath)
/// <returns></returns>
private string ManifestFragment(string key, string resourceString, string value, StreamWriter streamWriter)
{
return string.Format(CultureInfo.InvariantCulture, "{0}# {1}{2}{0}{3:19} = {4}{2}{2}",
_indent, resourceString, streamWriter.NewLine, key, value);
return string.Create(CultureInfo.InvariantCulture, $"{_indent}# {resourceString}{streamWriter.NewLine}{_indent}{key:19} = {value}{streamWriter.NewLine}{streamWriter.NewLine}");
}

private string ManifestFragmentForNonSpecifiedManifestMember(string key, string resourceString, string value, StreamWriter streamWriter)
{
return string.Format(CultureInfo.InvariantCulture, "{0}# {1}{2}{0}# {3:19} = {4}{2}{2}",
_indent, resourceString, streamWriter.NewLine, key, value);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What could we use to replace streamWriter.NewLine?

Copy link
Collaborator

@iSazonov iSazonov Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Environment.NewLine but only for test. If you think this is a root of issue revert the change to string.Format.

Copy link
Contributor Author

@CarloToso CarloToso Jan 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewModuleManifestCommand.cs is the problem (after we merge #18996 and #18997 we can close this PR)

return string.Create(CultureInfo.InvariantCulture, $"{_indent}# {resourceString}{streamWriter.NewLine}{_indent}{key:19} = {value}{streamWriter.NewLine}{streamWriter.NewLine}");
}

private static string ManifestComment(string insert, StreamWriter streamWriter)
Expand All @@ -904,7 +902,7 @@ private static string ManifestComment(string insert, StreamWriter streamWriter)
insert = " " + insert;
}

return string.Format(CultureInfo.InvariantCulture, "#{0}{1}", insert, streamWriter.NewLine);
return string.Create(CultureInfo.InvariantCulture, $"#{insert}{streamWriter.NewLine}");
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/debugger/debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5302,9 +5302,9 @@ private void DisplayScript(PSHost host, IList<PSObject> output, InvocationInfo i
{
WriteLine(
lineNumber == invocationInfo.ScriptLineNumber ?
string.Format(CultureInfo.CurrentCulture, "{0,5}:* {1}", lineNumber, _lines[lineNumber - 1])
string.Create(CultureInfo.CurrentCulture, $"{lineNumber,5}:* { _lines[lineNumber - 1]}")
:
string.Format(CultureInfo.CurrentCulture, "{0,5}: {1}", lineNumber, _lines[lineNumber - 1]),
string.Create(CultureInfo.CurrentCulture, $"{lineNumber,5}: { _lines[lineNumber - 1]}"),
host,
output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,10 @@ runspace.ConnectionInfo is VMConnectionInfo ||
!string.IsNullOrEmpty(sshConnectionInfo.UserName) &&
!System.Environment.UserName.Equals(sshConnectionInfo.UserName, StringComparison.Ordinal))
{
return string.Format(CultureInfo.InvariantCulture, "[{0}@{1}]: {2}", sshConnectionInfo.UserName, sshConnectionInfo.ComputerName, basePrompt);
return string.Create(CultureInfo.InvariantCulture, $"[{sshConnectionInfo.UserName}@{sshConnectionInfo.ComputerName}]: {basePrompt}");
}

return string.Format(CultureInfo.InvariantCulture, "[{0}]: {1}", runspace.ConnectionInfo.ComputerName, basePrompt);
return string.Create(CultureInfo.InvariantCulture, $"[{runspace.ConnectionInfo.ComputerName}]: {basePrompt}");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override
string
ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0},{1}", X, Y);
return string.Create(CultureInfo.InvariantCulture, $"{X},{Y}");
}

/// <summary>
Expand Down Expand Up @@ -257,7 +257,7 @@ public override
string
ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0},{1}", Width, Height);
return string.Create(CultureInfo.InvariantCulture, $"{Width},{Height}");
}

/// <summary>
Expand Down Expand Up @@ -566,7 +566,7 @@ public override
string
ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", VirtualKeyCode, Character, ControlKeyState, KeyDown);
return string.Create(CultureInfo.InvariantCulture, $"{VirtualKeyCode},{Character},{ControlKeyState},{KeyDown}");
}
/// <summary>
/// Overrides <see cref="System.Object.Equals(object)"/>
Expand Down Expand Up @@ -796,7 +796,7 @@ 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}");
}

/// <summary>
Expand Down Expand Up @@ -1024,7 +1024,7 @@ public override
string
ToString()
{
return string.Format(CultureInfo.InvariantCulture, "'{0}' {1} {2} {3}", Character, ForegroundColor, BackgroundColor, BufferCellType);
return string.Create(CultureInfo.InvariantCulture, $"'{Character}' {ForegroundColor} {BackgroundColor} {BufferCellType}");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ internal static void BuildHotkeysAndPlainLabels(Collection<ChoiceDescription> ch
if (string.Equals(hotkeysAndPlainLabels[0, i], "?", StringComparison.Ordinal))
{
Exception e = PSTraceSource.NewArgumentException(
string.Format(Globalization.CultureInfo.InvariantCulture, "choices[{0}].Label", i),
string.Create(Globalization.CultureInfo.InvariantCulture, $"choices[{i}].Label"),
InternalHostUserInterfaceStrings.InvalidChoiceHotKeyError);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Create(CultureInfo.InvariantCulture, $"{PSTask.RunspaceName}:{taskId}");

if (_useRunspacePool && _runspacePool.TryDequeue(out Runspace runspace))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Create(CultureInfo.InvariantCulture, $"->{Index} C({ContinuationStackDepth}) S({StackDepth})");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal void Define(LabelScopeInfo block)
{
if (j.ContainsTarget(_node))
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Label target already defined: {0}", _node.Name));
throw new InvalidOperationException(string.Create(CultureInfo.InvariantCulture, $"Label target already defined: {_node.Name}"));
}
}

Expand Down Expand Up @@ -132,7 +132,7 @@ private void ValidateJump(LabelScopeInfo reference)

if (HasMultipleDefinitions)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Ambiguous jump {0}", _node.Name));
throw new InvalidOperationException(string.Create(CultureInfo.InvariantCulture, $"Ambiguous jump {_node.Name}"));
}

// We didn't find an outward jump. Look for a jump across blocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public override string ToString()
StartIndex, EndIndex,
HandlerStartIndex, HandlerEndIndex
);
//return string.Create(CultureInfo.InvariantCulture, $"{(IsFault ? "fault" : "catch(" + ExceptionType.Name + ")")} [{StartIndex}-{EndIndex}] [{HandlerStartIndex}->{HandlerEndIndex}]");
}
}

Expand Down Expand Up @@ -231,11 +232,11 @@ public override string ToString()
{
if (IsClear)
{
return string.Format(CultureInfo.InvariantCulture, "{0}: clear", Index);
return string.Create(CultureInfo.InvariantCulture, $"{Index}: clear");
}
else
{
return string.Format(CultureInfo.InvariantCulture, "{0}: [{1}-{2}] '{3}'", Index, StartLine, EndLine, FileName);
return string.Create(CultureInfo.InvariantCulture, $"{Index}: [{StartLine}-{EndLine}] '{FileName}'");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ internal Expression LoadFromArray(Expression frameData, Expression closure)
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0}: {1} {2}", Index, IsBoxed ? "boxed" : null, InClosure ? "in closure" : null);
//return string.Create(CultureInfo.InvariantCulture, $"{Index}: {(IsBoxed ? "boxed" : null)} {(InClosure ? "in closure" : null)}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override int Run(InterpretedFrame frame)

public override string ToDebugString(int instructionIndex, object cookie, Func<int, int> labelIndexer, IList<object> objects)
{
return string.Format(CultureInfo.InvariantCulture, "LoadCached({0}: {1})", _index, objects[(int)_index]);
return string.Create(CultureInfo.InvariantCulture, $"LoadCached({_index}: {objects[(int)_index]})");
}

public override string ToString()
Expand Down