System.Reflection.Emit
名前空間を使用して、2D 配列構築用の IL を生成したいと考えています。
私のC#コードは
Array 2dArr = Array.CreateInstance(typeof(int),100,100);
を使用ildasm
すると、上記の C# コードに対して次の IL コードが生成されることがわかりました。
IL_0006: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
IL_000b: ldc.i4.s 100
IL_000d: ldc.i4.s 100
IL_000f: call class [mscorlib]System.Array [mscorlib]System.Array::CreateInstance(class [mscorlib]System.Type,
int32,
int32)
以下に示すように、最後の 3 つの IL ステートメントを生成できました。
MethodInfo createArray = typeof(Array).GetMethod("CreateInstance",
new Type[] { typeof(Type),typeof(int),typeof(int) });
gen.Emit(OpCodes.Ldc_I4_1);
gen.Emit(OpCodes.Ldc_I4_1);
gen.Emit(OpCodes.Call, createArray);
しかし、最初のILステートメントを生成する方法について明確な考えがありません(つまりIL_0006: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle
))
何か考えはありますか?
さらに、誰かが System.Reflection.Emit 名前空間を使用して IL コードを生成する方法について、いくつかの優れたチュートリアル/ドキュメントを指摘できますか?