MarshalExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace SoundIOSharp
  4. {
  5. public static class MarshalEx
  6. {
  7. public static double ReadDouble(IntPtr handle, int offset = 0)
  8. {
  9. return BitConverter.Int64BitsToDouble(Marshal.ReadInt64(handle, offset));
  10. }
  11. public static void WriteDouble(IntPtr handle, double value)
  12. {
  13. WriteDouble(handle, 0, value);
  14. }
  15. public static void WriteDouble(IntPtr handle, int offset, double value)
  16. {
  17. Marshal.WriteInt64(handle, offset, BitConverter.DoubleToInt64Bits(value));
  18. }
  19. public static float ReadFloat(IntPtr handle, int offset = 0)
  20. {
  21. return BitConverter.Int32BitsToSingle(Marshal.ReadInt32(handle, offset));
  22. }
  23. public static void WriteFloat(IntPtr handle, float value)
  24. {
  25. WriteFloat(handle, 0, value);
  26. }
  27. public static void WriteFloat(IntPtr handle, int offset, float value)
  28. {
  29. Marshal.WriteInt32(handle, offset, BitConverter.SingleToInt32Bits(value));
  30. }
  31. }
  32. }