GetVariableIndex() static private method

static private GetVariableIndex ( Mono.Cecil.Cil.VariableDefinition variable ) : int
variable Mono.Cecil.Cil.VariableDefinition
return int
        private void WriteOperand(Instruction instruction)
        {
            OpCode      opCode      = instruction.opcode;
            OperandType operandType = opCode.OperandType;

            if (operandType == OperandType.InlineNone)
            {
                return;
            }
            object obj = instruction.operand;

            if (obj == null)
            {
                throw new ArgumentException();
            }
            switch (operandType)
            {
            case OperandType.InlineBrTarget:
            {
                Instruction instruction1 = (Instruction)obj;
                base.WriteInt32(this.GetTargetOffset(instruction1) - (instruction.Offset + opCode.Size + 4));
                return;
            }

            case OperandType.InlineField:
            case OperandType.InlineMethod:
            case OperandType.InlineTok:
            case OperandType.InlineType:
            {
                this.WriteMetadataToken(this.metadata.LookupToken((IMetadataTokenProvider)obj));
                return;
            }

            case OperandType.InlineI:
            {
                base.WriteInt32((int)obj);
                return;
            }

            case OperandType.InlineI8:
            {
                base.WriteInt64((long)obj);
                return;
            }

            case OperandType.InlineNone:
            case OperandType.InlinePhi:
            {
                throw new ArgumentException();
            }

            case OperandType.InlineR:
            {
                base.WriteDouble((double)obj);
                return;
            }

            case OperandType.InlineSig:
            {
                this.WriteMetadataToken(this.GetStandAloneSignature((Mono.Cecil.CallSite)obj));
                return;
            }

            case OperandType.InlineString:
            {
                this.WriteMetadataToken(new MetadataToken(Mono.Cecil.TokenType.String, this.GetUserStringIndex((string)obj)));
                return;
            }

            case OperandType.InlineSwitch:
            {
                Instruction[] instructionArray = (Instruction[])obj;
                base.WriteInt32((int)instructionArray.Length);
                int offset = instruction.Offset + opCode.Size + 4 * ((int)instructionArray.Length + 1);
                for (int i = 0; i < (int)instructionArray.Length; i++)
                {
                    base.WriteInt32(this.GetTargetOffset(instructionArray[i]) - offset);
                }
                return;
            }

            case OperandType.InlineVar:
            {
                base.WriteInt16((short)CodeWriter.GetVariableIndex((VariableDefinition)obj));
                return;
            }

            case OperandType.InlineArg:
            {
                base.WriteInt16((short)this.GetParameterIndex((ParameterDefinition)obj));
                return;
            }

            case OperandType.ShortInlineBrTarget:
            {
                Instruction instruction2 = (Instruction)obj;
                base.WriteSByte((sbyte)(this.GetTargetOffset(instruction2) - (instruction.Offset + opCode.Size + 1)));
                return;
            }

            case OperandType.ShortInlineI:
            {
                if (opCode == OpCodes.Ldc_I4_S)
                {
                    base.WriteSByte((sbyte)obj);
                    return;
                }
                base.WriteByte((byte)obj);
                return;
            }

            case OperandType.ShortInlineR:
            {
                base.WriteSingle((float)obj);
                return;
            }

            case OperandType.ShortInlineVar:
            {
                base.WriteByte((byte)CodeWriter.GetVariableIndex((VariableDefinition)obj));
                return;
            }

            case OperandType.ShortInlineArg:
            {
                base.WriteByte((byte)this.GetParameterIndex((ParameterDefinition)obj));
                return;
            }

            default:
            {
                throw new ArgumentException();
            }
            }
        }