24 lines
663 B
C#
24 lines
663 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using OpenTK.Graphics.OpenGL4;
|
|
|
|
namespace hexworld.Util
|
|
{
|
|
public static class Extensions
|
|
{
|
|
public static byte[] ToBytes<T>(this T[] arr) where T : struct
|
|
{
|
|
var size = Marshal.SizeOf<T>()*arr.Length;
|
|
var bytes = new byte[size];
|
|
var ptr = Marshal.AllocHGlobal(size);
|
|
Marshal.StructureToPtr(arr, ptr, false);
|
|
Marshal.Copy(ptr, bytes, 0, size);
|
|
Marshal.FreeHGlobal(ptr);
|
|
return bytes;
|
|
}
|
|
}
|
|
} |