Xamarin Public Jenkins (auto-signing) ef583813eb Imported Upstream version 6.4.0.137
Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
2019-07-26 19:53:28 +00:00

44 lines
758 B
C#

using System.Runtime.InteropServices;
namespace System
{
partial class WeakReference
{
bool trackResurrection;
GCHandle handle;
public virtual bool IsAlive {
get {
return Target != null;
}
}
public virtual object Target {
get {
if (!handle.IsAllocated)
return null;
return handle.Target;
}
set {
handle.Target = value;
}
}
~WeakReference ()
{
handle.Free ();
}
void Create (object target, bool trackResurrection)
{
if (trackResurrection) {
this.trackResurrection = true;
handle = GCHandle.Alloc (target, GCHandleType.WeakTrackResurrection);
} else {
handle = GCHandle.Alloc (target, GCHandleType.Weak);
}
}
bool IsTrackResurrection () => trackResurrection;
}
}