here's a little test function I'm trying to do.  It should operate like
this:

public void Methodname()
{
   if{this.fieldName<0) {System.Console.WriteLine("hello zero")}
}

here's where I try and generate this:

        (fun (worker:CilWorker)->

            worker.Append (worker.Create( OpCodes.Ldc_I4_0 ))
            worker.Append (worker.Create( OpCodes.Ldarg_0 ))
            worker.Append (worker.Create( OpCodes.Ldfld, field))
            worker.Append (worker.Create( OpCodes.Clt ))
            let jump = worker.Create( OpCodes.Brtrue )
            worker.Append(jump)
            worker.Append(worker.Create(OpCodes.Ldstr, "hello zero"))

            let mi = (typeof<System.Console>).GetMethod("WriteLine",
[|typeof<string>|]) in let methodRef:MethodReference =
builder.GetMethodReference(mi)
            worker.Append(worker.Create(OpCodes.Call, methodRef) )
            let e = worker.Create( OpCodes.Ret)
            worker.Append(e)
            jump.Operand <- e
        )

You might notice that set the jump instruction operand at the end, after
I've generated my return opcode.  However this isn't working.  The stack
trace starts with "System.ArgumentException: opcode".  What am I doing
wrong?

thanks
Mike
-- 
--
mono-cecil

Reply via email to