AsmResolver.Net.Msil.MsilDisassembler.ResolveOperand C# (CSharp) Method

ResolveOperand() private method

private ResolveOperand ( IList instructions, MsilInstruction current ) : void
instructions IList
current MsilInstruction
return void
        private void ResolveOperand(IList<MsilInstruction> instructions, MsilInstruction current)
        {
            var nextOffset = current.Offset + current.Size;

            switch (current.OpCode.OperandType)
            {
                case MsilOperandType.InlineArgument:
                case MsilOperandType.ShortInlineArgument:
                    var parameter = _resolver.ResolveParameter(Convert.ToInt32(current.Operand));
                    if (parameter != null)
                        current.Operand = parameter;
                    break;

                case MsilOperandType.InlineVar:
                case MsilOperandType.ShortInlineVar:
                    var variable = _resolver.ResolveVariable(Convert.ToInt32(current.Operand));
                    if (variable != null)
                        current.Operand = variable;
                    break;

                case MsilOperandType.ShortInlineBrTarget:
                case MsilOperandType.InlineBrTarget:
                    var targetInstruction = instructions.FirstOrDefault(
                        x => x.Offset == nextOffset + Convert.ToInt32(current.Operand));
                    if (targetInstruction != null)
                        current.Operand = targetInstruction;
                    break;

                case MsilOperandType.InlineField:
                case MsilOperandType.InlineMethod:
                case MsilOperandType.InlineSig:
                case MsilOperandType.InlineTok:
                case MsilOperandType.InlineType:
                    var member = _resolver.ResolveMember((MetadataToken)current.Operand);
                    if (member != null)
                        current.Operand = member;
                    break;

                case MsilOperandType.InlineString:
                    var stringValue = _resolver.ResolveString(((MetadataToken)current.Operand).ToUInt32());
                    if (stringValue != null)
                        current.Operand = stringValue;
                    break;

                case MsilOperandType.InlineSwitch:
                    var targetOffsets = (int[])current.Operand;
                    var targets = new MsilInstruction[targetOffsets.Length];
                    for (int i = 0; i < targetOffsets.Length; i++)
                        targets[i] = instructions.FirstOrDefault(
                            x => x.Offset == nextOffset + targetOffsets[i]);
                    current.Operand = targets;
                    break;
            }
        }