It'*_*ie. 7 c# portable-class-library windows-phone-8
我正在尝试在PCL中使用此代码,我希望在WP8应用程序中使用它:
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;
}
Run Code Online (Sandbox Code Playgroud)
但是,它没有注册GCHandle或Marshal.有没有办法使用这些,或者在使用允许的类时是否有其他方法可以做到这一点?