godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ObjectExtensions.cs
2021-09-22 06:38:00 +02:00

32 lines
716 B
C#

using System;
using Godot.NativeInterop;
namespace Godot
{
public partial class Object
{
public static bool IsInstanceValid(Object instance)
{
return instance != null && instance.NativeInstance != IntPtr.Zero;
}
public static WeakRef WeakRef(Object obj)
{
if (!IsInstanceValid(obj))
return null;
using godot_ref weakRef = default;
unsafe
{
NativeFuncs.godotsharp_weakref(GetPtr(obj), &weakRef);
}
if (weakRef.IsNull)
return null;
return (WeakRef)InteropUtils.UnmanagedGetManaged(weakRef._reference);
}
}
}