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

39 lines
685 B
C#

using System.Runtime.InteropServices;
namespace System
{
partial class WeakReference<T>
{
GCHandle handle;
bool trackResurrection;
T Target {
get {
GCHandle h = handle;
return h.IsAllocated ? (T) h.Target : null;
}
}
~WeakReference ()
{
handle.Free ();
}
void Create (T target, bool trackResurrection)
{
if (trackResurrection) {
trackResurrection = true;
handle = GCHandle.Alloc (target, GCHandleType.WeakTrackResurrection);
} else {
handle = GCHandle.Alloc (target, GCHandleType.Weak);
}
}
public void SetTarget (T target)
{
handle.Target = target;
}
bool IsTrackResurrection () => trackResurrection;
}
}