diff --git a/Harmony/Extras/DelegateTypeFactory.cs b/Harmony/Extras/DelegateTypeFactory.cs
index a6ff5e22..ff8ad130 100644
--- a/Harmony/Extras/DelegateTypeFactory.cs
+++ b/Harmony/Extras/DelegateTypeFactory.cs
@@ -15,9 +15,9 @@ public class DelegateTypeFactory
public DelegateTypeFactory()
{
counter++;
- var name = "HarmonyDTFAssembly" + counter;
+ var name = $"HarmonyDTFAssembly{counter}";
var assembly = PatchTools.DefineDynamicAssembly(name);
- module = assembly.DefineDynamicModule("HarmonyDTFModule" + counter);
+ module = assembly.DefineDynamicModule($"HarmonyDTFModule{counter}");
}
/// Creates a delegate type for a method
@@ -27,7 +27,7 @@ public DelegateTypeFactory()
public Type CreateDelegateType(MethodInfo method)
{
var attr = TypeAttributes.Sealed | TypeAttributes.Public;
- var typeBuilder = module.DefineType("HarmonyDTFType" + counter, attr, typeof(MulticastDelegate));
+ var typeBuilder = module.DefineType($"HarmonyDTFType{counter}", attr, typeof(MulticastDelegate));
var constructor = typeBuilder.DefineConstructor(
MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public,
diff --git a/Harmony/Extras/FastAccess.cs b/Harmony/Extras/FastAccess.cs
index 46605558..613824ab 100644
--- a/Harmony/Extras/FastAccess.cs
+++ b/Harmony/Extras/FastAccess.cs
@@ -48,7 +48,7 @@ public static InstantiationHandler CreateInstantiationHandler()
typeof(T)));
}
- var dynamicMethod = new DynamicMethod("InstantiateObject_" + typeof(T).Name,
+ var dynamicMethod = new DynamicMethod($"InstantiateObject_{typeof(T).Name}",
MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard, typeof(T), null, typeof(T),
true);
var generator = dynamicMethod.GetILGenerator();
@@ -159,12 +159,12 @@ public static InstantiationHandler CreateInstantiationHandler()
static DynamicMethod CreateGetDynamicMethod(Type type)
{
- return new DynamicMethod("DynamicGet_" + type.Name, typeof(S), new Type[] { typeof(T) }, type, true);
+ return new DynamicMethod($"DynamicGet_{type.Name}", typeof(S), new Type[] { typeof(T) }, type, true);
}
static DynamicMethod CreateSetDynamicMethod(Type type)
{
- return new DynamicMethod("DynamicSet_" + type.Name, typeof(void), new Type[] { typeof(T), typeof(S) }, type,
+ return new DynamicMethod($"DynamicSet_{type.Name}", typeof(void), new Type[] { typeof(T), typeof(S) }, type,
true);
}
}
diff --git a/Harmony/Extras/MethodInvoker.cs b/Harmony/Extras/MethodInvoker.cs
index 3678be09..959b3ad9 100644
--- a/Harmony/Extras/MethodInvoker.cs
+++ b/Harmony/Extras/MethodInvoker.cs
@@ -75,7 +75,7 @@ public MethodInvoker(bool directBoxValueAccess = false)
/// The fast invocation handler
public FastInvokeHandler Handler(MethodInfo methodInfo, Module module)
{
- var dynamicMethod = new DynamicMethod("FastInvoke_" + methodInfo.Name + "_" + (directBoxValueAccess ? "direct" : "indirect"), typeof(object), new Type[] { typeof(object), typeof(object[]) }, module, true);
+ var dynamicMethod = new DynamicMethod($"FastInvoke_{methodInfo.Name}_{(directBoxValueAccess ? "direct" : "indirect")}", typeof(object), new Type[] { typeof(object), typeof(object[]) }, module, true);
var il = dynamicMethod.GetILGenerator();
if (!methodInfo.IsStatic)
diff --git a/Harmony/Internal/Emitter.cs b/Harmony/Internal/Emitter.cs
index 5cf8f9ba..184e6331 100644
--- a/Harmony/Internal/Emitter.cs
+++ b/Harmony/Internal/Emitter.cs
@@ -70,13 +70,13 @@ internal static string FormatArgument(object argument)
return ((MethodInfo)argument).FullDescription();
if (type == typeof(string))
- return "\"" + argument + "\"";
+ return $"\"{argument}\"";
if (type == typeof(Label))
- return "Label" + ((Label)argument).GetHashCode();
+ return $"Label{((Label)argument).GetHashCode()}";
if (type == typeof(Label[]))
- return "Labels" + string.Join(",", ((Label[])argument).Select(l => l.GetHashCode().ToString()).ToArray());
+ return $"Labels{string.Join(",", ((Label[])argument).Select(l => l.GetHashCode().ToString()).ToArray())}";
if (type == typeof(LocalBuilder))
- return ((LocalBuilder)argument).LocalIndex + " (" + ((LocalBuilder)argument).LocalType + ")";
+ return $"{((LocalBuilder)argument).LocalIndex} ({((LocalBuilder)argument).LocalType})";
return argument.ToString().Trim();
}
@@ -111,7 +111,7 @@ internal static void MarkBlockBefore(ILGenerator il, ExceptionBlock block, out L
FileLog.ChangeIndent(-1);
FileLog.LogBuffered("} // end try");
- FileLog.LogBuffered(".catch " + block.catchType);
+ FileLog.LogBuffered($".catch {block.catchType}");
FileLog.LogBuffered("{");
FileLog.ChangeIndent(1);
}
diff --git a/Harmony/Internal/ILInstruction.cs b/Harmony/Internal/ILInstruction.cs
index 6cd43a80..f5efebc8 100644
--- a/Harmony/Internal/ILInstruction.cs
+++ b/Harmony/Internal/ILInstruction.cs
@@ -77,7 +77,7 @@ public override string ToString()
var instruction = "";
AppendLabel(ref instruction, this);
- instruction = instruction + ": " + opcode.Name;
+ instruction += $": {opcode.Name}";
if (operand == null)
return instruction;
@@ -103,7 +103,7 @@ public override string ToString()
break;
case OperandType.InlineString:
- instruction = instruction + "\"" + operand + "\"";
+ instruction += $"\"{operand}\"";
break;
default:
@@ -117,10 +117,7 @@ public override string ToString()
static void AppendLabel(ref string str, object argument)
{
var instruction = argument as ILInstruction;
- if (instruction != null)
- str = str + "IL_" + instruction.offset.ToString("X4");
- else
- str = str + "IL_" + argument;
+ str += $"IL_{instruction?.offset.ToString("X4") ?? argument}";
}
}
}
\ No newline at end of file
diff --git a/Harmony/Internal/MethodCopier.cs b/Harmony/Internal/MethodCopier.cs
index 03546812..d89c2a46 100644
--- a/Harmony/Internal/MethodCopier.cs
+++ b/Harmony/Internal/MethodCopier.cs
@@ -66,11 +66,11 @@ internal MethodBodyReader(MethodBase method, ILGenerator generator)
var body = method.GetMethodBody();
if (body == null)
- throw new ArgumentException("Method " + method.FullDescription() + " has no body");
+ throw new ArgumentException($"Method {method.FullDescription()} has no body");
var bytes = body.GetILAsByteArray();
if (bytes == null)
- throw new ArgumentException("Can not get IL bytes of method " + method.FullDescription());
+ throw new ArgumentException($"Can not get IL bytes of method {method.FullDescription()}");
ilBytes = new ByteBuffer(bytes);
ilInstructions = new List((bytes.Length + 1) / 2);
@@ -338,8 +338,8 @@ internal void FinalizeILCodes(List transpilers, List