Last active
November 16, 2016 12:56
-
-
Save aevitas/d915a1163623e84013d635cf65aac4e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override unsafe T Read<T>(IntPtr address, bool isRelative = false) | |
{ | |
Requires.NotEqual(address, IntPtr.Zero, nameof(address)); | |
// We can bypass the marshal completely, unless the type we're reading has marshalling | |
// directives such as a [MarshalAs] attribute. | |
bool requiresMarshal = MarshalCache<T>.TypeRequiresMarshal; | |
var size = requiresMarshal ? MarshalCache<T>.Size : Unsafe.SizeOf<T>(); | |
var buffer = ReadBytes(address, size, isRelative); | |
fixed (byte* b = buffer) | |
{ | |
if (requiresMarshal) | |
return Marshal.PtrToStructure<T>(new IntPtr(b)); | |
return Unsafe.Read<T>(b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment