Deprecate string format shorthand.

This commit is contained in:
Matthias Mailänder
2023-05-03 20:27:36 +02:00
committed by abcdefg30
parent 1c2ce0dcc0
commit 65c0cf1065
12 changed files with 20 additions and 29 deletions

View File

@@ -27,11 +27,6 @@ namespace OpenRA
return string.Compare(str.ToUpperInvariant(), str, false) == 0;
}
public static string F(this string format, params object[] args)
{
return string.Format(format, args);
}
public static T WithDefault<T>(T def, Func<T> f)
{
try { return f(); }

View File

@@ -96,15 +96,11 @@ namespace OpenRA.Traits
.ToArray();
if (Footprint.Length == 0)
throw new ArgumentException(("This frozen actor has no footprint.\n" +
"Actor Name: {0}\n" +
"Actor Location: {1}\n" +
"Input footprint: [{2}]\n" +
"Input footprint (after shroud.Contains): [{3}]")
.F(actor.Info.Name,
actor.Location.ToString(),
footprint.Select(p => p.ToString()).JoinWith("|"),
footprint.Select(p => shroud.Contains(p).ToString()).JoinWith("|")));
throw new ArgumentException("This frozen actor has no footprint.\n" +
$"Actor Name: {actor.Info.Name}\n" +
$"Actor Location: {actor.Location}\n" +
$"Input footprint: [{footprint.Select(p => p.ToString()).JoinWith("|")}]\n" +
$"Input footprint (after shroud.Contains): [{footprint.Select(p => shroud.Contains(p).ToString()).JoinWith("|")}]");
CenterPosition = actor.CenterPosition;

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Scripting
{
var carryable = target.TraitOrDefault<Carryable>();
if (carryable == null)
throw new LuaException("Actor '{0}' cannot carry actor '{1}'!".F(Self, target));
throw new LuaException($"Actor '{Self}' cannot carry actor '{target}'!");
Self.QueueActivity(new PickupUnit(Self, target, carryall.Info.BeforeLoadDelay, null));
}

View File

@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits
if (countdownLabel != null)
{
countdown = new CachedTransform<int, string>(t =>
info.CountdownText.F(WidgetUtils.FormatTime(t, w.Timestep)));
string.Format(info.CountdownText, WidgetUtils.FormatTime(t, w.Timestep)));
countdownLabel.GetText = () => TimeLimit > 0 ? countdown.Update(ticksRemaining) : "";
}
}
@@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Traits
{
if (ticksRemaining == m * 60 * ticksPerSecond)
{
TextNotificationsManager.AddSystemLine(Notification.F(m, m > 1 ? "s" : null));
TextNotificationsManager.AddSystemLine(string.Format(Notification, m, m > 1 ? "s" : null));
var faction = self.World.LocalPlayer?.Faction.InternalName;
Game.Sound.PlayNotification(self.World.Map.Rules, self.World.LocalPlayer, "Speech", info.TimeLimitWarnings[m], faction);

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
var output = HtmlTemplate.JoinWith("\n").F(zoom, Convert.ToBase64String(modData.ModFiles.Open(image).ReadAllBytes()), "[" + regions.JoinWith(",") + "]");
var output = string.Format(HtmlTemplate.JoinWith("\n"), zoom, Convert.ToBase64String(modData.ModFiles.Open(image).ReadAllBytes()), "[" + regions.JoinWith(",") + "]");
var outputPath = Path.ChangeExtension(image, ".html");
File.WriteAllLines(outputPath, new[] { output });
Console.WriteLine("Saved {0}", outputPath);

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Widgets
var scale = 200 / Math.Max(5000, (float)Math.Ceiling(maxValue / 1000) * 1000);
var widthMaxValue = labelFont.Measure(GetYAxisValueFormat().F(height / scale)).X;
var widthMaxValue = labelFont.Measure(string.Format(GetYAxisValueFormat(), height / scale)).X;
var widthLongestName = labelFont.Measure(longestName).X;
// y axis label
@@ -164,7 +164,7 @@ namespace OpenRA.Mods.Common.Widgets
}), 1, color);
if (lastPoint != 0f)
labelFont.DrawTextWithShadow(GetValueFormat().F(lastPoint), graphOrigin + new float2(lastX * xStep, -lastPoint * scale - 2),
labelFont.DrawTextWithShadow(string.Format(GetValueFormat(), lastPoint), graphOrigin + new float2(lastX * xStep, -lastPoint * scale - 2),
color, BackgroundColorDark, BackgroundColorLight, 1);
}
@@ -185,7 +185,7 @@ namespace OpenRA.Mods.Common.Widgets
if (n % XAxisTicksPerLabel != 0)
continue;
var xAxisText = GetXAxisValueFormat().F(n / XAxisTicksPerLabel);
var xAxisText = string.Format(GetXAxisValueFormat(), n / XAxisTicksPerLabel);
var xAxisTickTextWidth = labelFont.Measure(xAxisText).X;
var xLocation = x - xAxisTickTextWidth / 2;
labelFont.DrawTextWithShadow(xAxisText,
@@ -202,7 +202,7 @@ namespace OpenRA.Mods.Common.Widgets
{
var yValue = y / scale;
cr.DrawLine(graphOrigin + new float2(0, -y), graphOrigin + new float2(5, -y), 1, Color.White);
var text = GetYAxisValueFormat().F(yValue);
var text = string.Format(GetYAxisValueFormat(), yValue);
var textWidth = labelFont.Measure(text);

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
siloUsageTooltip = siloUsageTooltipCache.Update((playerResources.Resources, playerResources.ResourceCapacity));
cashLabel.Text = cashTemplate.F(displayResources);
cashLabel.Text = string.Format(cashTemplate, displayResources);
}
}
}

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var requiresSize = int2.Zero;
if (prereqs.Any())
{
requiresLabel.Text = requiresFormat.F(prereqs.JoinWith(", "));
requiresLabel.Text = string.Format(requiresFormat, prereqs.JoinWith(", "));
requiresSize = requiresFont.Measure(requiresLabel.Text);
requiresLabel.Visible = true;
descLabel.Bounds.Y = descLabelY + requiresLabel.Bounds.Height;

View File

@@ -425,7 +425,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
titleLabel.GetText = () => item.Title;
var authorDateTimeLabel = newsItem.Get<LabelWidget>("AUTHOR_DATETIME");
var authorDateTime = authorDateTimeLabel.Text.F(item.Author, item.DateTime.ToLocalTime());
var authorDateTime = string.Format(authorDateTimeLabel.Text, item.Author, item.DateTime.ToLocalTime());
authorDateTimeLabel.GetText = () => authorDateTime;
var contentLabel = newsItem.Get<LabelWidget>("CONTENT");

View File

@@ -220,14 +220,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
duplicateNotice.IsVisible = () => !isHotkeyValid;
var duplicateNoticeText = new CachedTransform<HotkeyDefinition, string>(hd =>
hd != null ?
duplicateNotice.Text.F(hd.Description, hd.Contexts.First(c => selectedHotkeyDefinition.Contexts.Contains(c))) :
string.Format(duplicateNotice.Text, hd.Description, hd.Contexts.First(c => selectedHotkeyDefinition.Contexts.Contains(c))) :
"");
duplicateNotice.GetText = () => duplicateNoticeText.Update(duplicateHotkeyDefinition);
var originalNotice = panel.Get<LabelWidget>("ORIGINAL_NOTICE");
originalNotice.TextColor = ChromeMetrics.Get<Color>("NoticeInfoColor");
originalNotice.IsVisible = () => isHotkeyValid && !isHotkeyDefault;
var originalNoticeText = new CachedTransform<HotkeyDefinition, string>(hd => originalNotice.Text.F(hd?.Default.DisplayString()));
var originalNoticeText = new CachedTransform<HotkeyDefinition, string>(hd => string.Format(originalNotice.Text, hd?.Default.DisplayString()));
originalNotice.GetText = () => originalNoticeText.Update(selectedHotkeyDefinition);
var readonlyNotice = panel.Get<LabelWidget>("READONLY_NOTICE");

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets
{
var self = p.Instances[0].Self;
var time = WidgetUtils.FormatTime(p.RemainingTicks, false, self.World.Timestep);
var text = Format.F(self.Owner.PlayerName, p.Info.Name, time);
var text = string.Format(Format, self.Owner.PlayerName, p.Info.Name, time);
var playerColor = self.Owner.Color;
if (Game.Settings.Game.UsePlayerStanceColors)

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Platforms.Default
{
VerifyThreadAffinity();
if (!Exts.IsPowerOf2(width) || !Exts.IsPowerOf2(height))
throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height));
throw new InvalidDataException($"Non-power-of-two array {width}x{height}");
Size = new Size(width, height);
unsafe