Converts the structure to the raw bytes. Supported only for structures with simple types and no GC objects. The structure type. The structure value. The bytes array that contains a structure data.
(ref T value)
| 523 | /// <param name="value">The structure value.</param> |
| 524 | /// <returns>The bytes array that contains a structure data.</returns> |
| 525 | public static byte[] StructureToByteArray<T>(ref T value) where T : struct |
| 526 | { |
| 527 | // #stupid c# |
| 528 | int size = Marshal.SizeOf(typeof(T)); |
| 529 | byte[] arr = new byte[size]; |
| 530 | IntPtr ptr = Marshal.AllocHGlobal(size); |
| 531 | Marshal.StructureToPtr(value, ptr, true); |
| 532 | Marshal.Copy(ptr, arr, 0, size); |
| 533 | Marshal.FreeHGlobal(ptr); |
| 534 | return arr; |
| 535 | } |
| 536 | |
| 537 | /// <summary> |
| 538 | /// Converts the structure to the raw bytes. Supported only for structures with simple types and no GC objects. |
no test coverage detected