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

@@ -18,14 +18,14 @@ namespace OpenRA.Scripting
{
readonly Actor actor;
protected override string DuplicateKeyError(string memberName) { return "Actor '{0}' defines the command '{1}' on multiple traits".F(actor.Info.Name, memberName); }
protected override string DuplicateKeyError(string memberName) { return $"Actor '{actor.Info.Name}' defines the command '{memberName}' on multiple traits"; }
protected override string MemberNotFoundError(string memberName)
{
var actorName = actor.Info.Name;
if (actor.IsDead)
actorName += " (dead)";
return "Actor '{0}' does not define a property '{1}'".F(actorName, memberName);
return $"Actor '{actorName}' does not define a property '{memberName}'";
}
public ScriptActorInterface(ScriptContext context, Actor actor)

View File

@@ -81,8 +81,8 @@ namespace OpenRA.Scripting
/// </remarks>
public abstract class ScriptGlobal : ScriptObjectWrapper
{
protected override string DuplicateKeyError(string memberName) { return "Table '{0}' defines multiple members '{1}'".F(Name, memberName); }
protected override string MemberNotFoundError(string memberName) { return "Table '{0}' does not define a property '{1}'".F(Name, memberName); }
protected override string DuplicateKeyError(string memberName) { return $"Table '{Name}' defines multiple members '{memberName}'"; }
protected override string MemberNotFoundError(string memberName) { return $"Table '{Name}' does not define a property '{memberName}'"; }
public readonly string Name;
public ScriptGlobal(ScriptContext context)
@@ -92,7 +92,7 @@ namespace OpenRA.Scripting
var type = GetType();
var names = type.GetCustomAttributes<ScriptGlobalAttribute>(true);
if (names.Length != 1)
throw new InvalidOperationException("[ScriptGlobal] attribute not found for global table '{0}'".F(type));
throw new InvalidOperationException($"[ScriptGlobal] attribute not found for global table '{type}'");
Name = names.First().Name;
Bind(new[] { this });
@@ -187,7 +187,7 @@ namespace OpenRA.Scripting
});
if (ctor == null)
throw new InvalidOperationException("{0} must define a constructor that takes a ScriptContext context parameter".F(b.Name));
throw new InvalidOperationException($"{b.Name} must define a constructor that takes a ScriptContext context parameter");
var binding = (ScriptGlobal)ctor.Invoke(new[] { this });
using (var obj = binding.ToLuaValue(this))
@@ -236,7 +236,7 @@ namespace OpenRA.Scripting
using (var registerGlobal = (LuaFunction)runtime.Globals["RegisterSandboxedGlobal"])
{
if (runtime.Globals.ContainsKey(name))
throw new LuaException("The global name '{0}' is reserved, and may not be used by a map actor".F(name));
throw new LuaException($"The global name '{name}' is reserved, and may not be used by a map actor");
using (var obj = a.ToLuaValue(this))
registerGlobal.Call(name, obj).Dispose();

View File

@@ -32,16 +32,16 @@ namespace OpenRA.Scripting
ret = t.Name;
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>))
ret = "{0}?".F(t.GetGenericArguments().Select(p => p.Name).First());
ret = $"{t.GetGenericArguments().Select(p => p.Name).First()}?";
return ret;
}
public static string LuaDocString(this ParameterInfo pi)
{
var ret = "{0} {1}".F(pi.ParameterType.LuaDocString(), pi.Name);
var ret = $"{pi.ParameterType.LuaDocString()} {pi.Name}";
if (pi.IsOptional)
ret += " = {0}".F(pi.DefaultValue != null ? pi.DefaultValue : "nil");
ret += $" = {pi.DefaultValue ?? "nil"}";
return ret;
}
@@ -52,7 +52,7 @@ namespace OpenRA.Scripting
if (methodInfo != null)
{
var parameters = methodInfo.GetParameters().Select(pi => pi.LuaDocString());
return "{0} {1}({2})".F(methodInfo.ReturnType.LuaDocString(), mi.Name, parameters.JoinWith(", "));
return $"{methodInfo.ReturnType.LuaDocString()} {mi.Name}({parameters.JoinWith(", ")})";
}
var propertyInfo = mi as PropertyInfo;
@@ -64,10 +64,10 @@ namespace OpenRA.Scripting
if (propertyInfo.GetSetMethod() != null)
types.Add("set;");
return "{0} {1} {{ {2} }}".F(propertyInfo.PropertyType.LuaDocString(), mi.Name, types.JoinWith(" "));
return $"{propertyInfo.PropertyType.LuaDocString()} {mi.Name} {{ {types.JoinWith(" ")} }}";
}
return "Unknown field: {0}".F(mi.Name);
return $"Unknown field: {mi.Name}";
}
}
}

View File

@@ -62,14 +62,14 @@ namespace OpenRA.Scripting
if (i >= argCount)
{
if (!pi[i].IsOptional)
throw new LuaException("Argument '{0}' of '{1}' is not optional.".F(pi[i].LuaDocString(), Member.LuaDocString()));
throw new LuaException($"Argument '{pi[i].LuaDocString()}' of '{Member.LuaDocString()}' is not optional.");
clrArgs[i] = pi[i].DefaultValue;
continue;
}
if (!args[i].TryGetClrValue(pi[i].ParameterType, out clrArgs[i]))
throw new LuaException("Unable to convert parameter {0} to {1}".F(i, pi[i].ParameterType.Name));
throw new LuaException($"Unable to convert parameter {i} to {pi[i].ParameterType.Name}");
}
return mi.Invoke(Target, clrArgs).ToLuaValue(context);
@@ -105,7 +105,7 @@ namespace OpenRA.Scripting
if (IsGetProperty)
return ((PropertyInfo)Member).GetValue(Target, null).ToLuaValue(context);
throw new LuaException("The property '{0}' is write-only".F(Member.Name));
throw new LuaException($"The property '{Member.Name}' is write-only");
}
public void Set(LuaRuntime runtime, LuaValue value)
@@ -114,12 +114,12 @@ namespace OpenRA.Scripting
{
var pi = (PropertyInfo)Member;
if (!value.TryGetClrValue(pi.PropertyType, out var clrValue))
throw new LuaException("Unable to convert '{0}' to Clr type '{1}'".F(value.WrappedClrType().Name, pi.PropertyType));
throw new LuaException($"Unable to convert '{value.WrappedClrType().Name}' to Clr type '{pi.PropertyType}'");
pi.SetValue(Target, clrValue, null);
}
else
throw new LuaException("The property '{0}' is read-only".F(Member.Name));
throw new LuaException($"The property '{Member.Name}' is read-only");
}
public static IEnumerable<MemberInfo> WrappableMembers(Type t)

View File

@@ -18,8 +18,8 @@ namespace OpenRA.Scripting
{
readonly Player player;
protected override string DuplicateKeyError(string memberName) { return "Player '{0}' defines the command '{1}' on multiple traits".F(player.PlayerName, memberName); }
protected override string MemberNotFoundError(string memberName) { return "Player '{0}' does not define a property '{1}'".F(player.PlayerName, memberName); }
protected override string DuplicateKeyError(string memberName) { return $"Player '{player.PlayerName}' defines the command '{memberName}' on multiple traits"; }
protected override string MemberNotFoundError(string memberName) { return $"Player '{player.PlayerName}' does not define a property '{memberName}'"; }
public ScriptPlayerInterface(ScriptContext context, Player player)
: base(context)

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Scripting
if (!elementHasClrValue || !(element is LuaValue))
kv.Value.Dispose();
if (!elementHasClrValue)
throw new LuaException("Unable to convert table value of type {0} to type {1}".F(kv.Value.WrappedClrType(), innerType));
throw new LuaException($"Unable to convert table value of type {kv.Value.WrappedClrType()} to type {innerType}");
}
array.SetValue(element, i++);
@@ -186,7 +186,7 @@ namespace OpenRA.Scripting
return table;
}
throw new InvalidOperationException("Cannot convert type '{0}' to Lua. Class must implement IScriptBindable.".F(obj.GetType()));
throw new InvalidOperationException($"Cannot convert type '{obj.GetType()}' to Lua. Class must implement IScriptBindable.");
}
}
}