Obtain non-explicit field offset

后端 未结 2 1457
时光说笑
时光说笑 2021-01-12 06:59

I have the following class:

[StructLayout(LayoutKind.Sequential)]
class Class
{
    public int Field1;
    public byte Field2;
    public short? Field3;
             


        
2条回答
  •  一个人的身影
    2021-01-12 07:16

    With some tricks around TypedReference.MakeTypedReference, it is possible to obtain the reference to the field, and to the start of the object's data, then just subtract. The method can be found in SharpUtils.

提交回复
热议问题