Use string interpolation

Excludes Sprintf.cs
This commit is contained in:
YoshiRulz 2019-03-20 15:13:04 +10:00
parent d54146791e
commit 20b3112284
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
14 changed files with 36 additions and 37 deletions

View File

@ -117,8 +117,8 @@ namespace BizHawk.Common
.OrderBy(fi => (int)Marshal.OffsetOf(t, fi.Name))
.ToList();
var rmeth = new DynamicMethod(t.Name + "_r", null, new[] { typeof(object), typeof(BinaryReader) }, true);
var wmeth = new DynamicMethod(t.Name + "_w", null, new[] { typeof(object), typeof(BinaryWriter) }, true);
var rmeth = new DynamicMethod($"{t.Name}_r", null, new[] { typeof(object), typeof(BinaryReader) }, true);
var wmeth = new DynamicMethod($"{t.Name}_w", null, new[] { typeof(object), typeof(BinaryWriter) }, true);
{
var il = rmeth.GetILGenerator();
@ -134,7 +134,7 @@ namespace BizHawk.Common
MethodInfo m;
if (!Readhandlers.TryGetValue(field.FieldType, out m))
{
throw new InvalidOperationException("(R) Can't handle nested type " + field.FieldType);
throw new InvalidOperationException($"(R) Can't handle nested type {field.FieldType}");
}
il.Emit(OpCodes.Callvirt, m);
@ -159,7 +159,7 @@ namespace BizHawk.Common
MethodInfo m;
if (!Writehandlers.TryGetValue(field.FieldType, out m))
{
throw new InvalidOperationException("(W) Can't handle nested type " + field.FieldType);
throw new InvalidOperationException($"(W) Can't handle nested type {field.FieldType}");
}
il.Emit(OpCodes.Callvirt, m);

View File

@ -67,8 +67,7 @@ namespace BizHawk.Common.BizInvoke
.Where(a => a.Attr != null)
.ToList();
var typeBuilder = ImplModuleBuilder.DefineType(
"Bizhawk.BizExvokeHolder" + type.Name, TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed);
var typeBuilder = ImplModuleBuilder.DefineType($"Bizhawk.BizExvokeHolder{type.Name}", TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed);
foreach (var a in methods)
{

View File

@ -27,7 +27,7 @@ namespace BizHawk.Common.BizInvoke
// create the delegate type
var delegateType = enclosingType.DefineNestedType(
"DelegateType" + method.Name,
$"DelegateType{method.Name}",
TypeAttributes.Class | TypeAttributes.NestedPrivate | TypeAttributes.Sealed,
typeof(MulticastDelegate));
@ -85,7 +85,7 @@ namespace BizHawk.Common.BizInvoke
return new CustomAttributeBuilder(t.GetConstructor(Type.EmptyTypes), new object[0]);
}
throw new InvalidOperationException("Unknown parameter attribute " + t.Name);
throw new InvalidOperationException($"Unknown parameter attribute {t.Name}");
}
}
}

View File

@ -141,7 +141,7 @@ namespace BizHawk.Common.BizInvoke
var uo = baseMethods.FirstOrDefault(a => !a.Info.IsVirtual || a.Info.IsFinal);
if (uo != null)
{
throw new InvalidOperationException("Method " + uo.Info.Name + " cannot be overriden!");
throw new InvalidOperationException($"Method {uo.Info.Name} cannot be overriden!");
}
// there's no technical reason to disallow this, but we wouldn't be doing anything
@ -149,14 +149,14 @@ namespace BizHawk.Common.BizInvoke
var na = baseMethods.FirstOrDefault(a => !a.Info.IsAbstract);
if (na != null)
{
throw new InvalidOperationException("Method " + na.Info.Name + " is not abstract!");
throw new InvalidOperationException($"Method {na.Info.Name} is not abstract!");
}
}
// hooks that will be run on the created proxy object
var postCreateHooks = new List<Action<object, IImportResolver, ICallingConventionAdapter>>();
var type = ImplModuleBuilder.DefineType("Bizhawk.BizInvokeProxy" + baseType.Name, TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed, baseType);
var type = ImplModuleBuilder.DefineType($"Bizhawk.BizInvokeProxy{baseType.Name}", TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed, baseType);
var monitorField = monitor ? type.DefineField("MonitorField", typeof(IMonitor), FieldAttributes.Public) : null;
@ -210,7 +210,7 @@ namespace BizHawk.Common.BizInvoke
// define a field on the class to hold the delegate
var field = type.DefineField(
"DelegateField" + baseMethod.Name,
$"DelegateField{baseMethod.Name}",
delegateType,
FieldAttributes.Public);
@ -293,7 +293,7 @@ namespace BizHawk.Common.BizInvoke
// define a field on the type to hold the entry pointer
var field = type.DefineField(
"EntryPtrField" + baseMethod.Name,
$"EntryPtrField{baseMethod.Name}",
typeof(IntPtr),
FieldAttributes.Public);

View File

@ -100,7 +100,7 @@ namespace BizHawk.Common.BufferExtensions
for (int i = 0; i < buffer.Length && i * 2 < hex.Length; i++)
{
var bytehex = "" + hex[i * 2] + hex[(i * 2) + 1];
var bytehex = $"{hex[i * 2]}{hex[(i * 2) + 1]}";
buffer[i] = byte.Parse(bytehex, NumberStyles.HexNumber);
}
}
@ -136,7 +136,7 @@ namespace BizHawk.Common.BufferExtensions
for (int i = 0; i < buffer.Length && i * 4 < hex.Length; i++)
{
var shorthex = "" + hex[i * 4] + hex[(i * 4) + 1] + hex[(i * 4) + 2] + hex[(i * 4) + 3];
var shorthex = $"{hex[i * 4]}{hex[(i * 4) + 1]}{hex[(i * 4) + 2]}{hex[(i * 4) + 3]}";
buffer[i] = short.Parse(shorthex, NumberStyles.HexNumber);
}
}
@ -150,7 +150,7 @@ namespace BizHawk.Common.BufferExtensions
for (int i = 0; i < buffer.Length && i * 4 < hex.Length; i++)
{
var ushorthex = "" + hex[i * 4] + hex[(i * 4) + 1] + hex[(i * 4) + 2] + hex[(i * 4) + 3];
var ushorthex = $"{hex[i * 4]}{hex[(i * 4) + 1]}{hex[(i * 4) + 2]}{hex[(i * 4) + 3]}";
buffer[i] = ushort.Parse(ushorthex, NumberStyles.HexNumber);
}
}

View File

@ -7,32 +7,32 @@ namespace BizHawk.Common.NumberExtensions
{
public static string ToHexString(this int n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
return string.Format($"{{0:X{numdigits}}}", n);
}
public static string ToHexString(this uint n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
return string.Format($"{{0:X{numdigits}}}", n);
}
public static string ToHexString(this byte n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
return string.Format($"{{0:X{numdigits}}}", n);
}
public static string ToHexString(this ushort n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
return string.Format($"{{0:X{numdigits}}}", n);
}
public static string ToHexString(this long n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
return string.Format($"{{0:X{numdigits}}}", n);
}
public static string ToHexString(this ulong n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
return string.Format($"{{0:X{numdigits}}}", n);
}
public static bool Bit(this byte b, int index)

View File

@ -334,7 +334,7 @@ namespace BizHawk.Common
_extractor.ExtractFile(archiveIndex, _boundStream);
_boundStream.Position = 0;
_memberPath = _archiveItems[index].Name; // TODO - maybe go through our own list of names? maybe not, its indexes dont match..
Console.WriteLine("HawkFile bound " + CanonicalFullPath);
Console.WriteLine($"HawkFile bound {CanonicalFullPath}");
_boundIndex = archiveIndex;
return this;
}
@ -360,7 +360,7 @@ namespace BizHawk.Common
private void BindRoot()
{
_boundStream = _rootStream;
Console.WriteLine("HawkFile bound " + CanonicalFullPath);
Console.WriteLine($"HawkFile bound {CanonicalFullPath}");
}
/// <summary>

View File

@ -12,7 +12,7 @@ namespace BizHawk.Common
public InstanceDll(string dllPath)
{
// copy the dll to a temp directory
var path = TempFileManager.GetTempFilename(string.Format("{0}", Path.GetFileNameWithoutExtension(dllPath)),".dll",false);
var path = TempFileManager.GetTempFilename(Path.GetFileNameWithoutExtension(dllPath), ".dll", false);
using (var stream = new FileStream(path, FileMode.Create, System.Security.AccessControl.FileSystemRights.FullControl, FileShare.ReadWrite | FileShare.Delete, 4 * 1024, FileOptions.None))
using (var sdll = File.OpenRead(dllPath))
sdll.CopyTo(stream);
@ -24,7 +24,7 @@ namespace BizHawk.Common
var envpath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
try
{
string envpath_new = Path.GetDirectoryName(path) + ";" + envpath;
string envpath_new = $"{Path.GetDirectoryName(path)};{envpath}";
Environment.SetEnvironmentVariable("PATH", envpath_new, EnvironmentVariableTarget.Process);
_hModule = LoadLibrary(path); //consider using LoadLibraryEx instead of shenanigans?
if (_hModule == IntPtr.Zero)

View File

@ -107,10 +107,10 @@ namespace BizHawk.Common
public void Store(string name, byte[] buf, int offset, int length)
{
if (Items.ContainsKey(name))
throw new InvalidOperationException(string.Format("Can't add already existing key of name {0}", name));
throw new InvalidOperationException($"Can't add already existing key of name {name}");
if (length > Remain)
throw new OutOfMemoryException(string.Format("Insufficient storage reserved for {0} bytes", length));
throw new OutOfMemoryException($"Insufficient storage reserved for {length} bytes");
long todo = length;
int src = offset;

View File

@ -740,7 +740,7 @@ namespace BizHawk.Common
}
else
{
throw new Exception(string.Format("Duplicate key \"{0}\" in serializer savestate!", name));
throw new Exception($"Duplicate key \"{name}\" in serializer savestate!");
}
curs = news;
@ -763,7 +763,7 @@ namespace BizHawk.Common
}
else
{
throw new Exception(string.Format("Duplicate key \"{0}\" in serializer savestate!", key));
throw new Exception($"Duplicate key \"{key}\" in serializer savestate!");
}
}
}

View File

@ -50,7 +50,7 @@ namespace BizHawk.Common
private static DefaultValueSetter CreateSetter(Type t)
{
var dyn = new DynamicMethod("SetDefaultValues_" + t.Name, null, new[] { typeof(object), typeof(object[]) }, false);
var dyn = new DynamicMethod($"SetDefaultValues_{t.Name}", null, new[] { typeof(object), typeof(object[]) }, false);
var il = dyn.GetILGenerator();
List<object> DefaultValues = new List<object>();
@ -90,7 +90,7 @@ namespace BizHawk.Common
}
else
{
throw new InvalidOperationException(string.Format("Default value assignment will fail for {0}.{1}", t.Name, prop.Name));
throw new InvalidOperationException($"Default value assignment will fail for {t.Name}.{prop.Name}");
}
il.Emit(OpCodes.Callvirt, method);
}

View File

@ -37,7 +37,7 @@ namespace BizHawk.Common
throw new InvalidOperationException();
}
filename = "bizdelete-" + filename.Remove(0, 4);
filename = $"bizdelete-{filename.Remove(0, 4)}";
return Path.Combine(dir, filename);
}

View File

@ -389,7 +389,7 @@ namespace BizHawk.Common
}
const string precision = "2";
return string.Format("{0:N" + precision + "}{1}", size, suffix);
return string.Format($"{{0:N{precision}}}{{1}}", size, suffix);
}
// http://stackoverflow.com/questions/3928822/comparing-2-dictionarystring-string-instances
@ -510,7 +510,7 @@ namespace BizHawk.Common
static SuperGloballyUniqueID()
{
StaticPart = "bizhawk-" + System.Diagnostics.Process.GetCurrentProcess().Id + "-" + Guid.NewGuid();
StaticPart = $"bizhawk-{System.Diagnostics.Process.GetCurrentProcess().Id}-{Guid.NewGuid()}";
}
public static string Next()
@ -521,7 +521,7 @@ namespace BizHawk.Common
myctr = ctr++;
}
return StaticPart + "-" + myctr;
return $"{StaticPart}-{myctr}";
}
}

View File

@ -456,7 +456,7 @@ namespace BizHawk.Common
//I only put this for use here by external cores
public static void RemoveMOTW(string path)
{
DeleteFileW(path + ":Zone.Identifier");
DeleteFileW($"{path}:Zone.Identifier");
}
[DllImport("kernel32.dll")]