/// <summary> /// Removes this instance of BaseHandle (C# base class) and native part from the mapping table. /// </summary> /// <param name="baseHandle"> The instance of BaseHandle (C# base class)</param> internal static void Unregister(BaseHandle baseHandle) { IntPtr refCptr = Interop.BaseHandle.GetObjectPtr(baseHandle.GetBaseHandleCPtrHandleRef); RegistryCurrentThreadCheck(); WeakReference refe; if (Instance._controlMap.TryRemove(refCptr, out refe) != true) { NUILog.Debug("something wrong when removing refCptr!"); } NUILog.Debug($"[Registry] Unregister! type:{baseHandle.GetType()} count:{Instance._controlMap.Count} copyNativeHandle:{baseHandle.GetBaseHandleCPtrHandleRef.Handle.ToString("X8")}"); return; }
/// <summary> /// Stores the mapping between this instance of BaseHandle (C# base class) and native part. /// </summary> /// <param name="baseHandle">The instance of BaseHandle (C# base class).</param> internal static void Register(BaseHandle baseHandle) { // We store a pointer to the RefObject for the control IntPtr refCptr = Interop.BaseHandle.GetObjectPtr(baseHandle.GetBaseHandleCPtrHandleRef); RegistryCurrentThreadCheck(); if (Instance._controlMap.TryAdd(refCptr, new WeakReference(baseHandle, false)) != true) { NUILog.Debug("refCptr is already exist! OR something wrong!"); } NUILog.Debug($"[Registry] Register! type:{baseHandle.GetType()} count:{Instance._controlMap.Count} copyNativeHandle:{baseHandle.GetBaseHandleCPtrHandleRef.Handle.ToString("X8")}"); return; }