예를들어 클래스가 아래와같은 배열을 포함하고 있다면,
이걸 어떻게 byte[] 로 바꿀수 있는지 질문 드립니다.
배열이 포함되지 않은건 그냥 아래와같이 하면 되는데, 배열이 포함되면 사이즈도 제대로 안나오고,
변환도 안되네요.
==================================================
class a
{
int id;
byte[] arr = new byte[100];
}
public static int CvtStructToBin(object obj, out byte[] bin, int offset) { bin = new byte[Marshal.SizeOf(obj)]; unsafe { fixed (byte* fixed_buffer = &bin[offset]) { Marshal.StructureToPtr(obj, (IntPtr)fixed_buffer, false); } } return bin.Length; }