且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在运行时使用Emit的C#数组

更新时间:2023-12-06 16:41:52

如果我明白你想做什么,我不相信这是可能的.您要执行的操作类似于锯齿状数组: http://msdn.microsoft.com/en-us /library/2s05feca.aspx [ ^ ]
If I understand what you want to do, I do not beleive it is possible. What you want to do is similar to jagged arrays: http://msdn.microsoft.com/en-us/library/2s05feca.aspx[^]


我在数组中添加了一些内容,并将此代码添加到了代码生成器中,现在可以正常使用了:)

I made a few addition to my Arrays and added this code in the codegenerator and it works just fine now :)

Arrays arr = (Arrays)value;
deliveredType = arr.array.GetType();
Type myType = arr.array.GetType();
Type[] types = new Type[arr.dimensions.Length];
for (int i = 0; i < arr.dimensions.Length; i++)
{
    types[i] = arr.type;
    il.Emit(OpCodes.Ldc_I4, arr.dimensions[i]);
}

ConstructorInfo constructorInfoObj = myType.GetConstructor(types);


il.Emit(OpCodes.Newobj, constructorInfoObj);