I am trying to use this code in PCL, which I hope to use in a WP8 application:
internal static T ByteArrayToStructure<T>(byte[] bytes) where T : struct { GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); T value = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); try {} finally { handle.Free(); } return value; }
However, he does not register GCHandle or Marshal . Is there a way to use them, or is there another way to do this when using allowed classes?
source share