StringHash.cs 843 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Urho {
  4. [StructLayout(LayoutKind.Sequential)]
  5. public struct StringHash {
  6. public int Code;
  7. [Preserve]
  8. public StringHash (int code)
  9. {
  10. this.Code = code;
  11. }
  12. [Preserve]
  13. public StringHash (string str)
  14. {
  15. this.Code = urho_stringhash_from_string (str);
  16. }
  17. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  18. extern static int urho_stringhash_from_string (string str);
  19. public override string ToString ()
  20. {
  21. return $"StringHash({Code:x})";
  22. }
  23. }
  24. // Points to a StringHash
  25. public struct StringHashRef {
  26. IntPtr ptr;
  27. [Preserve]
  28. public StringHashRef (IntPtr ptr)
  29. {
  30. this.ptr = ptr;
  31. }
  32. public static implicit operator StringHash (StringHashRef r)
  33. {
  34. return new StringHash (Marshal.ReadInt32 (r.ptr));
  35. }
  36. }
  37. }