doc: SafeMemory.PtrToStructure

This commit is contained in:
goat 2021-12-07 22:19:21 +01:00
parent a3b217b3a0
commit 9d781518d6
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5

View file

@ -190,8 +190,20 @@ namespace Dalamud
return WriteBytes(address, encoding.GetBytes(str + "\0"));
}
/// <summary>
/// Marshals data from an unmanaged block of memory to a managed object.
/// </summary>
/// <typeparam name="T">The type to create.</typeparam>
/// <param name="addr">The address to read from.</param>
/// <returns>The read object, or null, if it could not be read.</returns>
public static T? PtrToStructure<T>(IntPtr addr) where T : struct => (T?)PtrToStructure(addr, typeof(T));
/// <summary>
/// Marshals data from an unmanaged block of memory to a managed object.
/// </summary>
/// <param name="addr">The address to read from.</param>
/// <param name="type">The type to create.</param>
/// <returns>The read object, or null, if it could not be read.</returns>
public static object? PtrToStructure(IntPtr addr, Type type)
{
var size = Marshal.SizeOf(type);