Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide public static API to create Instruction instances #15

Closed
KrisVandermotten opened this issue May 19, 2010 · 1 comment
Closed

Comments

@KrisVandermotten
Copy link

It should be possible to write the following method:

    public static void StartWithNop(Mono.Collections.Generic.Collection<Instruction> instructions)
    {
        Instruction nop = // maybe Instruction.Create(OpCodes.Nop, null);
        instructions.Insert(0, nop);
    }

Currently, the only way to create an instruction is via Create methods on ILProcessor. Obviously, this requires creating an instance of ILProcessor and passing it around. As this instance is not actually used by the Create methods, it seems rather pointless to create it and pass it around. Put differently: the Create methods can and should be static, in which case they belong on the Instruction class.

In the example above, the method currently needs and additional parameter, either an ILProcessor or a MethodBody.
In the case of passing an ILProcessor, there's no way that the method can check that the instructions parameter corresponds to the instructions collection hidden inside the ILProcessor (and hidden it is).
In the case of passing the MethodBody, the instructions collection does not need to be passed separately, but an ILProcessor must be created to be able to create an instruction.

Furthermore, creating instructions is the only thing that an ILProcessor is required for. Every other operation offered by ILProcessor is easy to do directly on an instructions collection.

I therefor propose the following:

  • static Create methods are added to the Instruction class
  • Create methods on ILProcessor delegate to Create methods on instruction class
  • Create methods on ILProcessor are marked obsolete
@jbevain
Copy link
Owner

jbevain commented May 25, 2010

Fixed. Thanks!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants