Mono.Cecil.Cil.CodeWriter.WriteOperand C# (CSharp) Method

WriteOperand() private method

private WriteOperand ( Instruction instruction ) : void
instruction Instruction
return void
        void WriteOperand(Instruction instruction)
        {
            var opcode = instruction.opcode;
            var operand_type = opcode.OperandType;
            if (operand_type == OperandType.InlineNone)
                return;

            var operand = instruction.operand;
            if (operand == null)
                throw new ArgumentException ();

            switch (operand_type) {
            case OperandType.InlineSwitch: {
                var targets = (Instruction []) operand;
                WriteInt32 (targets.Length);
                var diff = instruction.Offset + opcode.Size + (4 * (targets.Length + 1));
                for (int i = 0; i < targets.Length; i++)
                    WriteInt32 (GetTargetOffset (targets [i]) - diff);
                break;
            }
            case OperandType.ShortInlineBrTarget: {
                var target = (Instruction) operand;
                WriteSByte ((sbyte) (GetTargetOffset (target) - (instruction.Offset + opcode.Size + 1)));
                break;
            }
            case OperandType.InlineBrTarget: {
                var target = (Instruction) operand;
                WriteInt32 (GetTargetOffset (target) - (instruction.Offset + opcode.Size + 4));
                break;
            }
            case OperandType.ShortInlineVar:
                WriteByte ((byte) GetVariableIndex ((VariableDefinition) operand));
                break;
            case OperandType.ShortInlineArg:
                WriteByte ((byte) GetParameterIndex ((ParameterDefinition) operand));
                break;
            case OperandType.InlineVar:
                WriteInt16 ((short) GetVariableIndex ((VariableDefinition) operand));
                break;
            case OperandType.InlineArg:
                WriteInt16 ((short) GetParameterIndex ((ParameterDefinition) operand));
                break;
            case OperandType.InlineSig:
                WriteMetadataToken (GetStandAloneSignature ((CallSite) operand));
                break;
            case OperandType.ShortInlineI:
                if (opcode == OpCodes.Ldc_I4_S)
                    WriteSByte ((sbyte) operand);
                else
                    WriteByte ((byte) operand);
                break;
            case OperandType.InlineI:
                WriteInt32 ((int) operand);
                break;
            case OperandType.InlineI8:
                WriteInt64 ((long) operand);
                break;
            case OperandType.ShortInlineR:
                WriteSingle ((float) operand);
                break;
            case OperandType.InlineR:
                WriteDouble ((double) operand);
                break;
            case OperandType.InlineString:
                WriteMetadataToken (
                    new MetadataToken (
                        TokenType.String,
                        GetUserStringIndex ((string) operand)));
                break;
            case OperandType.InlineType:
            case OperandType.InlineField:
            case OperandType.InlineMethod:
            case OperandType.InlineTok:
                WriteMetadataToken (metadata.LookupToken ((IMetadataTokenProvider) operand));
                break;
            default:
                throw new ArgumentException ();
            }
        }