Question

When I waas looking at OpCodes class source code, I noticed something weird.

OpCodes class contains some static readonly fields of type OpCode struct.For example:

public static readonly OpCode Nop = new OpCode(OpCodeValues.Nop, 6556325);

That creates a new OpCode and pass it two parameter. but when I look at the OpCode struct I can't find any constructor that takes two parameter.Instead there is just one internal constructor and it looks like this:

    internal OpCode(String stringname, 
                    StackBehaviour pop, 
                    StackBehaviour push, 
                    OperandType operand, 
                    OpCodeType type, 
                    int size, byte s1, byte s2, 
                    FlowControl ctrl, 
                    bool endsjmpblk, int stack) 

As far as I can see there is no optional parameters here.

So where is that constructor ? Is there an invisible constructor somewhere?

Note: I'm using .NET Reflector

Was it helpful?

Solution

Apparently you are looking at the 2.0 version of mscorlib. That version has an OpCode struct with the 11 parameter constructor. Newer versions of mscorlib, at least with 4.0, contain an OpCode constructor containing only 2 parameters

OTHER TIPS

I think you're looking in the wrong place.

enter image description here

As found in mscorlib.System.Reflection.Emit.OpCode (using ILSpy)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top