/// <summary>
        /// Add an instruction's operand to <paramref name="sb"/>
        /// </summary>
        /// <param name="sb">Place result here</param>
        /// <param name="instr">The instruction</param>
        /// <param name="extra">A string that will be added before the operand, if there's
        /// an operand.</param>
        public static void AddOperandString(StringBuilder sb, Instruction instr, string extra)
        {
            var op = instr.Operand;

            switch (instr.OpCode.OperandType)
            {
            case OperandType.InlineBrTarget:
            case OperandType.ShortInlineBrTarget:
                sb.Append(extra);
                AddInstructionTarget(sb, op as Instruction);
                break;

            case OperandType.InlineField:
            case OperandType.InlineMethod:
            case OperandType.InlineTok:
            case OperandType.InlineType:
                sb.Append(extra);
                if (op is IFullName)
                {
                    sb.Append((op as IFullName).FullName);
                }
                else if (op != null)
                {
                    sb.Append(op.ToString());
                }
                else
                {
                    sb.Append("null");
                }
                break;

            case OperandType.InlineI:
            case OperandType.InlineI8:
            case OperandType.InlineR:
            case OperandType.ShortInlineI:
            case OperandType.ShortInlineR:
                sb.Append($"{extra}{op}");
                break;

            case OperandType.InlineSig:
                sb.Append(extra);
                sb.Append(FullNameFactory.MethodFullName(null, (UTF8String)null, op as MethodSig, null, null, null, null));
                break;

            case OperandType.InlineString:
                sb.Append(extra);
                EscapeString(sb, op as string, true);
                break;

            case OperandType.InlineSwitch:
                var targets = op as IList <Instruction>;
                if (targets == null)
                {
                    sb.Append("null");
                }
                else
                {
                    sb.Append('(');
                    for (int i = 0; i < targets.Count; i++)
                    {
                        if (i != 0)
                        {
                            sb.Append(',');
                        }
                        AddInstructionTarget(sb, targets[i]);
                    }
                    sb.Append(')');
                }
                break;

            case OperandType.InlineVar:
            case OperandType.ShortInlineVar:
                sb.Append(extra);
                if (op == null)
                {
                    sb.Append("null");
                }
                else
                {
                    sb.Append(op.ToString());
                }
                break;

            case OperandType.InlineNone:
            case OperandType.InlinePhi:
            default:
                break;
            }
        }
Esempio n. 2
0
 public override string ToString()
 {
     return(FullNameFactory.MethodFullName("", Name, MethodSig));
 }