문제

Using ILDasm to reverse engineer some C# code, I found out that the compiler uses the System.Runtime.CompilerServices.RuntimeHelper.InitializeArraymethod to initialize arrays that contain several constant values of primitive types.

Looks like it creates a special structure for each array size in bytes and marks it with [StructLayout] attribute. This is pretty straightforward. But then there is a field of that type that contains the actual data. How do I create a field like that in terms of Reflection.Emit and fill it with arbitrary bytes?

도움이 되었습니까?

해결책

I think you use ModuleBuilder.DefineInitializedData for that.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top