1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System
.Runtime
.InteropServices
;
9 partial class WeakReference
<T
>
12 bool trackResurrection
;
17 return h
.IsAllocated
? (T
) h
.Target
: null;
26 void Create (T target
, bool trackResurrection
)
28 if (trackResurrection
) {
29 trackResurrection
= true;
30 handle
= GCHandle
.Alloc (target
, GCHandleType
.WeakTrackResurrection
);
32 handle
= GCHandle
.Alloc (target
, GCHandleType
.Weak
);
36 public void SetTarget (T target
)
38 handle
.Target
= target
;
41 bool IsTrackResurrection () => trackResurrection
;