NativeWrapper.cs 648 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Linq;
  5. namespace Helper
  6. {
  7. public static class NativeWrapper
  8. {
  9. public static System.IntPtr GetNativePtr(Object obj)
  10. {
  11. if(obj == null)
  12. {
  13. return System.IntPtr.Zero;
  14. }
  15. var nativeWrapperIface = obj as INativeWrapper;
  16. if(nativeWrapperIface != null)
  17. {
  18. return nativeWrapperIface.nativePtr;
  19. }
  20. else
  21. {
  22. throw new ArgumentException("Object must wrap native type");
  23. }
  24. }
  25. }
  26. }