I'm trying to emit what I thought would be a simple array of objects, which will cause the code to look like the example below
object[] parameters = new object[] { a, b, };
When I write the above code in C # using VS, I get the following IL. As expected, this works.
.locals init (
[0] object[] parameters,
[1] object[] CS$0$0000)
However, when I try to run Emit IL directly, I get only one init init array. Can someone help me tell where I was wrong here?
Here is the Emit code I'm using:
int arraySize = 2;
LocalBuilder paramValues = ilGenerator.DeclareLocal(typeof(object[]));
paramValues.SetLocalSymInfo("parameters");
ilGenerator.Emit(OpCodes.Ldc_I4_S, arraySize);
ilGenerator.Emit(OpCodes.Newarr, typeof(object));
ilGenerator.Emit(OpCodes.Stloc, paramValues);
Here is the result of IL:
.locals init (
[0] object[] objArray)
The rest of the resulting IL is identical between the two solutions, but for some reason .locals init is different.
source
share