U should not only set Operand in copied instruction - u should also
import TypeReference or whatever from target assembly to destination
one. In other case (using old object) u will get invalid result.
Of course, u should do almost everyting by yourself.

On Nov 8, 11:52 am, Stanislav <[email protected]> wrote:
> I need instruction duplicating too. I need to inject instructions of
> some method to another one.
>
> On 7 ноя, 01:46, Simon Cropp <[email protected]> wrote:
>
>
>
> > i looked at various overloads of Instruction.Create and it seemed I
> > would need to do a if,else,else etc on my operand type.
>
> > The other option was to call Instruction.Create(OpCode) and then set
> > the Operand property.
>
> > But that failed because of this check
>
> > public static Instruction Create(OpCode opcode)
> > {
> >     if (opcode.OperandType != OperandType.InlineNone)
> >     {
> >         throw new ArgumentException("opcode");
> >     }
> >     return new Instruction(opcode, null);
>
> > }
>
> > If I already have a valid instruction should there not be a
> > Instruction.Clone(Instruction)  ?
>
> > On Sun, Nov 7, 2010 at 9:35 AM, Jb Evain <[email protected]> wrote:
> > > Hey,
>
> > > On Sat, Nov 6, 2010 at 10:42 PM, Simon Cropp <[email protected]> 
> > > wrote:
> > >> Ok I obviously misunderstood what the import does :) I have this working 
> > >> now.
>
> > > Cool :)
>
> > >> And I did not use Instruction.Create because there is no
> > >> Instruction.Create(Instruction).
>
> > > Right, there's something missing here. Maybe not Instruction.Create
> > > but Instruction.Create(OpCode,object).
>
> > > --
> > > --
> > > mono-cecil- Hide quoted text -
>
> - Show quoted text -

-- 
--
mono-cecil

Reply via email to