1 using System; 2 using System.Runtime.CompilerServices; 3 4 namespace Godot 5 { 6 public sealed partial class RID : IDisposable 7 { 8 private bool disposed = false; 9 10 internal IntPtr ptr; 11 GetPtr(RID instance)12 internal static IntPtr GetPtr(RID instance) 13 { 14 if (instance == null) 15 throw new NullReferenceException($"The instance of type {nameof(RID)} is null."); 16 17 if (instance.disposed) 18 throw new ObjectDisposedException(instance.GetType().FullName); 19 20 return instance.ptr; 21 } 22 ~RID()23 ~RID() 24 { 25 Dispose(false); 26 } 27 Dispose()28 public void Dispose() 29 { 30 Dispose(true); 31 GC.SuppressFinalize(this); 32 } 33 Dispose(bool disposing)34 private void Dispose(bool disposing) 35 { 36 if (disposed) 37 return; 38 39 if (ptr != IntPtr.Zero) 40 { 41 godot_icall_RID_Dtor(ptr); 42 ptr = IntPtr.Zero; 43 } 44 45 disposed = true; 46 } 47 RID(IntPtr ptr)48 internal RID(IntPtr ptr) 49 { 50 this.ptr = ptr; 51 } 52 53 public IntPtr NativeInstance 54 { 55 get { return ptr; } 56 } 57 RID()58 internal RID() 59 { 60 this.ptr = IntPtr.Zero; 61 } 62 RID(Object from)63 public RID(Object from) 64 { 65 this.ptr = godot_icall_RID_Ctor(Object.GetPtr(from)); 66 } 67 GetId()68 public int GetId() 69 { 70 return godot_icall_RID_get_id(RID.GetPtr(this)); 71 } 72 ToString()73 public override string ToString() => "[RID]"; 74 75 [MethodImpl(MethodImplOptions.InternalCall)] godot_icall_RID_Ctor(IntPtr from)76 internal extern static IntPtr godot_icall_RID_Ctor(IntPtr from); 77 78 [MethodImpl(MethodImplOptions.InternalCall)] godot_icall_RID_Dtor(IntPtr ptr)79 internal extern static void godot_icall_RID_Dtor(IntPtr ptr); 80 81 [MethodImpl(MethodImplOptions.InternalCall)] godot_icall_RID_get_id(IntPtr ptr)82 internal extern static int godot_icall_RID_get_id(IntPtr ptr); 83 } 84 } 85