4

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?

1 Answer 1

2

I think you use ModuleBuilder.DefineInitializedData for that.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Exactly what I've expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.