in binding/SkiaSharp/HandleDictionary.cs [104:130]
private static bool GetInstanceNoLocks<TSkiaObject> (IntPtr handle, out TSkiaObject instance)
where TSkiaObject : SKObject
{
if (instances.TryGetValue (handle, out var weak) && weak.IsAlive) {
if (weak.Target is TSkiaObject match) {
if (!match.IsDisposed) {
instance = match;
return true;
}
#if THROW_OBJECT_EXCEPTIONS
} else if (weak.Target is SKObject obj) {
if (!obj.IsDisposed && obj.OwnsHandle) {
throw new InvalidOperationException (
$"A managed object exists for the handle, but is not the expected type. " +
$"H: {handle.ToString ("x")} Type: ({obj.GetType ()}, {typeof (TSkiaObject)})");
}
} else if (weak.Target is object o) {
throw new InvalidOperationException (
$"An unknown object exists for the handle when trying to fetch an instance. " +
$"H: {handle.ToString ("x")} Type: ({o.GetType ()}, {typeof (TSkiaObject)})");
#endif
}
}
instance = null;
return false;
}