Files
WoWDBDefs/code/C#/DBDefsTest/Utils/BinaryReaderExtensions.cs
2018-02-24 15:09:30 +01:00

14 lines
409 B
C#

using System.IO;
using System.Runtime.InteropServices;
public static class Extensions
{
public static T Read<T>(this BinaryReader bin)
{
var bytes = bin.ReadBytes(Marshal.SizeOf(typeof(T)));
var handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
T ret = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
return ret;
}
}