private void WriteOperand(ITextOutput output, object operand, Dictionary <Instruction, string> labels, Dictionary <VariableReference, string> locals) { if (operand is MethodReference methodReference) { var methodDefinition = methodReference.Resolve(); output.WriteTypeOf(methodDefinition.DeclaringType); if (methodDefinition.IsGetter) { output.Write($".GetProperty(\"{methodDefinition.Name.Split('_')[1]}\").GetGetMethod(true)"); } else if (methodDefinition.IsSetter) { output.Write($".GetProperty(\"{methodDefinition.Name.Split('_')[1]}\").GetSetMethod(true)"); } else { if (methodDefinition.IsConstructor) { output.Write($".GetConstructor("); } else { output.Write($".GetMethod(\"{methodDefinition.Name}\","); } if (methodReference.HasParameters) { output.Write($"new Type[] {{ {string.Join(", ", methodDefinition.Parameters.Select(p => p.ParameterType.ToTypeOf()))} }}"); } else { output.Write("Type.EmptyTypes"); } output.Write(")"); } } else if (operand is string stringOperand) { output.Write($"\"{stringOperand}\""); } else if (operand is double doubleOperand) { output.Write(doubleOperand.ToString(CultureInfo.InvariantCulture)); } else if (operand is float floatOperand) { output.Write(floatOperand.ToString(CultureInfo.InvariantCulture)); } else if (operand is byte byteOperand) { output.Write(byteOperand.ToString(CultureInfo.InvariantCulture)); } else if (operand is int intOperand) { output.Write(intOperand.ToString(CultureInfo.InvariantCulture)); } else if (operand is long longOperand) { output.Write(longOperand.ToString(CultureInfo.InvariantCulture)); } else if (operand is sbyte sbyteOperand) { output.Write(sbyteOperand.ToString(CultureInfo.InvariantCulture)); } else if (operand is Instruction instruction) { output.Write(labels.Single(l => l.Key.Offset == instruction.Offset).Value); } else if (operand is Instruction[] instructions) { var labelParams = string.Join(", ", instructions.Select(i => labels[i])); output.Write($"new Label[] {{ {labelParams} }}"); } else if (operand is FieldReference fieldReference) { output.WriteTypeOf(fieldReference.FieldType); output.Write($".GetField(\"{fieldReference.Name}\", BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)"); } else if (operand is VariableReference variable) { output.Write(locals.Single(l => l.Key.Index == variable.Index).Value); } else if (operand is TypeReference type) { output.WriteTypeOf(type); } else if (operand is ParameterReference param) { output.Write(param.Index.ToString()); } else { output.WriteLine($"Unsupported parameter: {operand.GetType()}"); } }