Replace F extension with string interpolation

This commit is contained in:
teinarss
2021-04-24 17:46:24 +02:00
committed by reaperrr
parent 1385aca783
commit 10676be377
300 changed files with 752 additions and 799 deletions

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (!IsConditionalTrait(t))
continue;
var overridesCreated = t.GetMethod("{0}.{1}".F(interfaceType.FullName, methodName), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) != null;
var overridesCreated = t.GetMethod($"{interfaceType.FullName}.{methodName}", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) != null;
if (overridesCreated)
{
Console.WriteLine("{0} must override ConditionalTrait's {1} method instead of implementing {2} directly", t.Name, methodName, interfaceType.Name);

View File

@@ -68,12 +68,12 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
// The stacktrace associated with yaml errors are not very useful
// Suppress them to make the lint output less intimidating for modders
Console.WriteLine("\t{0}".F(e.Message));
Console.WriteLine($"\t{e.Message}");
failed = true;
}
catch (Exception e)
{
Console.WriteLine("Failed with exception: {0}".F(e));
Console.WriteLine($"Failed with exception: {e}");
failed = true;
}
}
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
// The stacktrace associated with yaml errors are not very useful
// Suppress them to make the lint output less intimidating for modders
Console.WriteLine("{0}".F(e.Message));
Console.WriteLine($"{e.Message}");
failed = true;
}

View File

@@ -52,13 +52,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
Log.AddChannel("perf", null);
// bind some nonfatal error handling into FieldLoader, so we don't just *explode*.
ObjectCreator.MissingTypeAction = s => EmitError("Missing Type: {0}".F(s));
FieldLoader.UnknownFieldAction = (s, f) => EmitError("FieldLoader: Missing field `{0}` on `{1}`".F(s, f.Name));
ObjectCreator.MissingTypeAction = s => EmitError($"Missing Type: {s}");
FieldLoader.UnknownFieldAction = (s, f) => EmitError($"FieldLoader: Missing field `{s}` on `{f.Name}`");
var maps = new List<Map>();
if (args.Length < 2)
{
Console.WriteLine("Testing mod: {0}".F(modData.Manifest.Metadata.Title));
Console.WriteLine($"Testing mod: {modData.Manifest.Metadata.Title}");
// Run all rule checks on the default mod rules.
CheckRules(modData, modData.DefaultRules);
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
catch (Exception e)
{
EmitError("{0} failed with exception: {1}".F(customPassType, e));
EmitError($"{customPassType} failed with exception: {e}");
}
}
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
foreach (var testMap in maps)
{
Console.WriteLine("Testing map: {0}".F(testMap.Title));
Console.WriteLine($"Testing map: {testMap.Title}");
// Lint tests can't be trusted if the map rules are bogus
// so report that problem then skip the tests
@@ -109,7 +109,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
catch (Exception e)
{
EmitError("{0} failed with exception: {1}".F(customMapPassType, e));
EmitError($"{customMapPassType} failed with exception: {e}");
}
}
}
@@ -122,7 +122,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
catch (Exception e)
{
EmitError("Failed with exception: {0}".F(e));
EmitError($"Failed with exception: {e}");
Environment.Exit(1);
}
}
@@ -138,7 +138,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
catch (Exception e)
{
EmitError("{0} failed with exception: {1}".F(customRulesPassType, e));
EmitError($"{customRulesPassType} failed with exception: {e}");
}
}
}

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
var png = new Png(pngData, SpriteFrameType.Indexed8, frameSize.Width, frameSize.Height, palColors);
png.Save("{0}-{1:D4}.png".F(prefix, count++));
png.Save($"{prefix}-{(count++):D4}.png");
}
Console.WriteLine("Saved {0}-[0..{1}].png", prefix, count - 1);

View File

@@ -49,10 +49,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
Console.WriteLine(".TP");
Console.Write(".BR {0}.{1}=".F(section.Key, field.Name));
Console.Write($".BR {section.Key}.{field.Name}=");
var value = field.GetValue(section.Value);
if (value != null && !value.ToString().StartsWith("System.", StringComparison.Ordinal))
Console.WriteLine("\\fI{0}\\fR".F(value));
Console.WriteLine($"\\fI{value}\\fR");
else
Console.WriteLine();

View File

@@ -63,14 +63,14 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
var r = s.Bounds;
if (c.Value.PanelSides.HasSide(s.PanelSides))
regions.Add("[\"{0}.<{1}>\",{2},{3},{4},{5}]".F(c.Key, s.PanelSides, r.X, r.Y, r.Width, r.Height));
regions.Add($"[\"{c.Key}.<{s.PanelSides}>\",{r.X},{r.Y},{r.Width},{r.Height}]");
}
}
foreach (var kv in c.Value.Regions)
{
var r = kv.Value;
regions.Add("[\"{0}\",{1},{2},{3},{4}]".F(c.Key + "." + kv.Key, r.X, r.Y, r.Width, r.Height));
regions.Add($"[\"{c.Key}.{kv.Key}\",{r.X},{r.Y},{r.Width},{r.Height}]");
}
}

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (mapPackage != null)
sequences = new Map(modData, mapPackage).Rules.Sequences;
else if (!modData.DefaultSequences.TryGetValue(args[2], out sequences))
throw new InvalidOperationException("{0} is not a valid tileset or map path".F(args[2]));
throw new InvalidOperationException($"{args[2]} is not a valid tileset or map path");
sequences.Preload();
@@ -50,12 +50,12 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
var max = s == sb.Current ? (int)sb.CurrentChannel + 1 : 4;
for (var i = 0; i < max; i++)
s.AsPng((TextureChannel)ChannelMasks[i], palette).Save("{0}.png".F(count++));
s.AsPng((TextureChannel)ChannelMasks[i], palette).Save($"{count++}.png");
}
sb = sequences.SpriteCache.SheetBuilders[SheetType.BGRA];
foreach (var s in sb.AllSheets)
s.AsPng().Save("{0}.png".F(count++));
s.AsPng().Save($"{count++}.png");
Console.WriteLine("Saved [0..{0}].png", count - 1);
}

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
var src = utility.ModData.DefaultFileSystem.Open(f);
if (src == null)
throw new InvalidOperationException("File not found: {0}".F(f));
throw new InvalidOperationException($"File not found: {f}");
var data = src.ReadAllBytes();
File.WriteAllBytes(f, data);
Console.WriteLine(f + " saved.");

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
foreach (var m in members.OrderBy(m => m.Name))
{
var desc = m.HasAttribute<DescAttribute>() ? m.GetCustomAttributes<DescAttribute>(true).First().Lines.JoinWith("\n") : "";
Console.WriteLine("<tr><td align=\"right\" width=\"50%\"><strong>{0}</strong></td><td>{1}</td></tr>".F(m.LuaDocString(), desc));
Console.WriteLine($"<tr><td align=\"right\" width=\"50%\"><strong>{m.LuaDocString()}</strong></td><td>{desc}</td></tr>");
}
Console.WriteLine("</table>");
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
Console.WriteLine("<br />");
if (hasRequires)
Console.WriteLine("<b>Requires {1}:</b> {0}".F(required.JoinWith(", "), required.Length == 1 ? "Trait" : "Traits"));
Console.WriteLine($"<b>Requires {(required.Length == 1 ? "Trait" : "Traits")}:</b> {required.JoinWith(", ")}");
Console.WriteLine("</td></tr>");
}
@@ -165,7 +165,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
Console.WriteLine("<br />");
if (hasRequires)
Console.WriteLine("<b>Requires {1}:</b> {0}".F(required.JoinWith(", "), required.Length == 1 ? "Trait" : "Traits"));
Console.WriteLine($"<b>Requires {(required.Length == 1 ? "Trait" : "Traits")}:</b> {required.JoinWith(", ")}");
Console.WriteLine("</td></tr>");
}

View File

@@ -53,13 +53,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
currentNamespace = t.Namespace;
doc.AppendLine();
doc.AppendLine("## {0}".F(currentNamespace));
doc.AppendLine($"## {currentNamespace}");
}
var traitName = t.Name.EndsWith("Info") ? t.Name.Substring(0, t.Name.Length - 4) : t.Name;
var traitDescLines = t.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines);
doc.AppendLine();
doc.AppendLine("### {0}".F(traitName));
doc.AppendLine($"### {traitName}");
foreach (var line in traitDescLines)
doc.AppendLine(line);
@@ -70,14 +70,14 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (t.HasAttribute<DescAttribute>())
doc.AppendLine();
doc.Append("Requires trait{0}: ".F(reqCount > 1 ? "s" : ""));
doc.Append($"Requires trait{(reqCount > 1 ? "s" : "")}: ");
var i = 0;
foreach (var require in requires)
{
var n = require.Name;
var name = n.EndsWith("Info") ? n.Remove(n.Length - 4, 4) : n;
doc.Append("[`{0}`](#{1}){2}".F(name, name.ToLowerInvariant(), i + 1 == reqCount ? ".\n" : ", "));
doc.Append($"[`{name}`](#{name.ToLowerInvariant()}){(i + 1 == reqCount ? ".\n" : ", ")}");
i++;
}
}
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
var fieldType = Util.FriendlyTypeName(info.Field.FieldType);
var loadInfo = info.Field.GetCustomAttributes<FieldLoader.SerializeAttribute>(true).FirstOrDefault();
var defaultValue = loadInfo != null && loadInfo.Required ? "<em>(required)</em>" : FieldSaver.SaveField(liveTraitInfo, info.Field.Name).Value.Value;
doc.Append("<tr><td>{0}</td><td>{1}</td><td>{2}</td>".F(info.YamlName, defaultValue, fieldType));
doc.Append($"<tr><td>{info.YamlName}</td><td>{defaultValue}</td><td>{fieldType}</td>");
doc.Append("<td>");
foreach (var line in fieldDescLines)
doc.Append(line + " ");

View File

@@ -63,12 +63,12 @@ namespace OpenRA.Mods.Common.UtilityCommands
{
currentNamespace = t.Namespace;
doc.AppendLine();
doc.AppendLine("## {0}".F(currentNamespace));
doc.AppendLine($"## {currentNamespace}");
}
var traitName = t.Name.EndsWith("Info") ? t.Name.Substring(0, t.Name.Length - 4) : t.Name;
doc.AppendLine();
doc.AppendLine("### {0}".F(traitName));
doc.AppendLine($"### {traitName}");
var traitDescLines = t.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines);
foreach (var line in traitDescLines)
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
var fieldDescLines = info.Field.GetCustomAttributes<DescAttribute>(true).SelectMany(d => d.Lines);
var fieldType = Util.FriendlyTypeName(info.Field.FieldType);
var defaultValue = liveTraitInfo == null ? "" : FieldSaver.SaveField(liveTraitInfo, info.Field.Name).Value.Value;
doc.Append("<tr><td>{0}</td><td>{1}</td><td>{2}</td>".F(info.YamlName, defaultValue, fieldType));
doc.Append($"<tr><td>{info.YamlName}</td><td>{defaultValue}</td><td>{fieldType}</td>");
doc.Append("<td>");
foreach (var line in fieldDescLines)

View File

@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
Console.WriteLine(" name = \"OpenRA\",");
Console.WriteLine(" description = \"Adds API description for auto-complete and tooltip support for OpenRA.\",");
Console.WriteLine(" author = \"Matthias Mailänder\",");
Console.WriteLine(" version = \"{0}\",".F(Game.ModData.Manifest.Metadata.Version.Split('-').LastOrDefault()));
Console.WriteLine($" version = \"{Game.ModData.Manifest.Metadata.Version.Split('-').LastOrDefault()}\",");
Console.WriteLine();
Console.WriteLine(" onRegister = function(self)");
Console.WriteLine(" ide:AddAPI(\"lua\", \"openra\", api)");

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
// The original game isn't case sensitive, but we are.
var tileset = GetTileset(mapSection).ToUpperInvariant();
if (!ModData.DefaultTerrainInfo.TryGetValue(tileset, out var terrainInfo))
throw new InvalidDataException("Unknown tileset {0}".F(tileset));
throw new InvalidDataException($"Unknown tileset {tileset}");
Map = new Map(ModData, terrainInfo, MapSize, MapSize)
{
@@ -299,8 +299,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
var parts = s.Value.Split(',');
var loc = Exts.ParseIntegerInvariant(parts[1]);
var type = parts[0].ToLowerInvariant();
var key = "{0},{1}".F(loc % MapSize, loc / MapSize);
var value = "{0},{1}".F(type, parts[2]);
var key = $"{loc % MapSize},{loc / MapSize}";
var value = $"{type},{parts[2]}";
var node = new MiniYamlNode(key, value);
if (type.StartsWith("sc"))
scorches.Add(node);
@@ -422,13 +422,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
var actorCount = map.ActorDefinitions.Count;
if (!map.Rules.Actors.ContainsKey(parts[1].ToLowerInvariant()))
Console.WriteLine("Ignoring unknown actor type: `{0}`".F(parts[1].ToLowerInvariant()));
Console.WriteLine($"Ignoring unknown actor type: `{parts[1].ToLowerInvariant()}`");
else
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, actor.Save()));
}
catch (Exception)
{
Console.WriteLine("Malformed actor definition: `{0}`".F(s));
Console.WriteLine($"Malformed actor definition: `{s}`");
}
}
}

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
var playerCount = 0;
foreach (var p in info.Players)
{
var playerLines = FieldSaver.Save(p).ToLines("{0}".F(playerCount++));
var playerLines = FieldSaver.Save(p).ToLines($"{playerCount++}");
foreach (var line in playerLines)
Console.WriteLine("\t\t" + line);
}

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (!map.Contains(locationInit.Value))
{
Console.WriteLine("Removing actor {0} located at {1} due being outside of the new map boundaries.".F(actor.Type, locationInit.Value));
Console.WriteLine($"Removing actor {actor.Type} located at {locationInit.Value} due being outside of the new map boundaries.");
forRemoval.Add(kv);
}
}