I think what you propose is the best way to achieve this. I'm not sure
if 'ret' is the only opcode that can leave a method normally, though.
Regards,
Alex
> --
> --
> mono-cecil
>Well, I tried that method but I get way too many return operations in
some situations like when a switch operation occurs in the method.
Moreover, if I fear that simply injecting my code before the
OpCodes.Ret instruction wouldn't work neither in some cases like when
a value is returned by the method.
I don't think that's a problem as long as you correctly stabilize the stack.
Regards,
Alex
> --
> --
> mono-cecil
--
--
mono-cecil
--
--
mono-cecil
>If I use the last OpCodes.Ret, it actually injects my code in the if statement like so:
Right. You don't have much choice but to do control flow analysis
here; build a control flow graph from the IL and figure out where to
inject code.
>I'm not sure if the switch instruction can also cause the same problem.
Its operand is just an array of instruction pointers, so someone
certainly could write some pretty whacky code with that...
Regards,
Alex
> --
> --
> mono-cecil
This is much easier.
Jb
--
--
mono-cecil
Not more than injecting code at every ret point.
Jb
--
--
mono-cecil
>However, I have some PEVerify errors in assemblies that use Generics
stating that fields inside generic classes should be referenced using
MemberRefs even on the same module than the class. How can I solve
that?
Make a FieldReference and use that instead of a FieldDefinition in
whatever place you're getting the error.
Regards,
Alex
> --
> --
> mono-cecil
We have nice threads in this group about how to deal with generics.
Look them up.
Jb
You need to create one FieldDefinition for, well, the definition of
the field, and then for each usage, create a FieldReference with the
proper generic signature, based on the definition, search for
MakeGeneric*
Jb