I think you use ModuleBuilder.DefineInitializedData for that.
Mimicking C# array initializer behaviour using Reflection
-
24-03-2022 - |
Question
Using ILDasm to reverse engineer some C# code, I found out that the compiler uses the System.Runtime.CompilerServices.RuntimeHelper.InitializeArray
method 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?
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow