internal void ToString(TextBuilder text) { if (this.ILGeneratorMethod != ILGeneratorMethod.None) { text.Append(this.ILGeneratorMethod) .Append('('); if (this.Argument is IEnumerable args) { text.AppendDelimit(',', args.AsObjectEnumerable(), (tb, a) => tb.AppendDump(a)); } else { text.AppendDump(this.Argument); } text.Append(')'); } else { var opCode = this.OpCode; AppendLabel(text, this); text.Append(": ") .Append(opCode.Name); var operand = this.Argument; if (operand is null) { return; } AppendOperand(text, opCode.OperandType, operand); } }
public static TextBuilder AppendDump(this TextBuilder textBuilder, Array?array, DumpOptions options = default) { textBuilder.Write('['); if (array != null) { textBuilder.AppendDelimit <object?>(", ", array.AsArrayEnumerable(), (tb, value) => tb.AppendDump(value, options)); } return(textBuilder.Append(']')); }
public static TextBuilder AppendDump(this TextBuilder textBuilder, IEnumerable?enumerable, DumpOptions options = default) { textBuilder.Write('('); if (enumerable != null) { textBuilder.AppendDelimit <object?>(", ", enumerable.AsObjectEnumerable(), (tb, value) => tb.AppendDump(value, options)); } return(textBuilder.Append(')')); }
public static TextBuilder AppendDump(this TextBuilder textBuilder, FieldInfo?field, DumpOptions options = default) { if (field is null) { if (options.Verbose) { return(textBuilder.Append("(FieldInfo)null")); } return(textBuilder); } if (options.Verbose) { var fieldAttributes = Attribute.GetCustomAttributes(field, true); if (fieldAttributes.Length > 0) { textBuilder.AppendDelimit(Environment.NewLine, fieldAttributes, (tb, attr) => tb.Append('[').Append(attr).Append(']')) .AppendLine(); } var visibility = field.GetVisibility(); if (visibility.HasFlag <Visibility>(Visibility.Private)) { textBuilder.Write("private "); } if (visibility.HasFlag <Visibility>(Visibility.Protected)) { textBuilder.Write("protected "); } if (visibility.HasFlag <Visibility>(Visibility.Internal)) { textBuilder.Write("internal "); } if (visibility.HasFlag <Visibility>(Visibility.Public)) { textBuilder.Write("public "); } if (field.IsStatic) { textBuilder.Write("static "); } } return(textBuilder.AppendDump(field.FieldType, options) .Append(' ') .Append(field.Name)); }
private static void AppendOperand(TextBuilder text, OperandType operandType, object operand) { text.Append(' '); switch (operandType) { case OperandType.ShortInlineBrTarget: case OperandType.InlineBrTarget: { if (operand is Instruction opInst) { AppendLabel(text, opInst); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineSwitch: { if (operand is Instruction[] labels) { text.AppendDelimit(',', labels, AppendLabel !); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineString: { if (!(operand is string str)) { str = operand.ToString() ?? string.Empty; } text.Append('"') .Append(str) .Append('"'); break; } case OperandType.InlineField: { if (operand is FieldInfo field) { text.AppendDump(field); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineI: case OperandType.ShortInlineI: { if (operand is IntPtr intPtr) { text.AppendFormat(intPtr, "X"); } else if (operand is int integer) { text.Append(integer); } else if (operand is sbyte signedByte) { text.Append(signedByte); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineI8: { if (operand is byte b) { text.Append(b) .Append('b'); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineMethod: { if (operand is MethodBase methodBase) { text.AppendDump(methodBase); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineR: case OperandType.ShortInlineR: { if (operand is float f) { text.Append(f) .Append('f'); } else if (operand is double d) { text.Append(d) .Append('d'); } else if (operand is decimal m) { text.Append(m) .Append('m'); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineType: { if (operand is Type type) { text.AppendDump(type); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineTok: { if (operand is MemberInfo member) { text.AppendDump(member); } else { throw new InvalidOperationException(); } break; } case OperandType.InlineVar: case OperandType.ShortInlineVar: { // Variables? text.AppendDump(operand); break; } case OperandType.InlineNone: //case OperandType.InlinePhi: case OperandType.InlineSig: default: { Hold.Debug(operandType, operand); text.Append(operand); break; } } }
public static TextBuilder AppendDump(this TextBuilder textBuilder, PropertyInfo?property, DumpOptions options = default) { if (property is null) { if (options.Verbose) { return(textBuilder.Append("(PropertyInfo)null")); } return(textBuilder); } if (options.Verbose) { var fieldAttributes = Attribute.GetCustomAttributes(property, true); if (fieldAttributes.Length > 0) { textBuilder.AppendDelimit(Environment.NewLine, fieldAttributes, (tb, attr) => tb.Append('[').Append(attr).Append(']')) .AppendLine(); } var visibility = property.GetVisibility(); if (visibility.HasFlag <Visibility>(Visibility.Private)) { textBuilder.Write("private "); } if (visibility.HasFlag <Visibility>(Visibility.Protected)) { textBuilder.Write("protected "); } if (visibility.HasFlag <Visibility>(Visibility.Internal)) { textBuilder.Write("internal "); } if (visibility.HasFlag <Visibility>(Visibility.Public)) { textBuilder.Write("public "); } if (property.IsStatic()) { textBuilder.Write("static "); } } textBuilder.AppendDump(property.PropertyType, options) .Append(' ') .Append(property.Name); var indexParams = property.GetIndexParameters(); if (indexParams.Length > 0) { textBuilder.Append('[') .AppendDelimit(", ", indexParams, (tb, pi) => tb.AppendDump(pi, options)) .Append(']'); } // Getter + Setter textBuilder.Append(" { "); var getter = property.GetGetter(); if (getter != null) { if (options.Verbose) { } else { textBuilder.Append("get; "); } } var setter = property.GetSetter(); if (setter != null) { if (options.Verbose) { } else { textBuilder.Append("set; "); } } return(textBuilder.Append(" }")); }