PartialUnmapHelpers.cs 741 B

1234567891011121314151617181920
  1. using System.Runtime.CompilerServices;
  2. namespace Ryujinx.Common.Memory.PartialUnmaps
  3. {
  4. static class PartialUnmapHelpers
  5. {
  6. /// <summary>
  7. /// Calculates a byte offset of a given field within a struct.
  8. /// </summary>
  9. /// <typeparam name="T">Struct type</typeparam>
  10. /// <typeparam name="T2">Field type</typeparam>
  11. /// <param name="storage">Parent struct</param>
  12. /// <param name="target">Field</param>
  13. /// <returns>The byte offset of the given field in the given struct</returns>
  14. public static int OffsetOf<T, T2>(ref T2 storage, ref T target)
  15. {
  16. return (int)Unsafe.ByteOffset(ref Unsafe.As<T2, T>(ref storage), ref target);
  17. }
  18. }
  19. }