StringHash.cs 804 B

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