using System; using System.Runtime.InteropServices; using System.Runtime.Serialization; namespace System { /// Represents a weak reference, which references an object while still allowing that object to be reclaimed by garbage collection. /// 2 // Token: 0x020006C1 RID: 1729 [ComVisible(true)] [Serializable] public class WeakReference : ISerializable { // Token: 0x06004136 RID: 16694 RVA: 0x000DE574 File Offset: 0x000DC774 protected WeakReference() { } /// Initializes a new instance of the class, referencing the specified object. /// The object to track or null. // Token: 0x06004137 RID: 16695 RVA: 0x000DE57C File Offset: 0x000DC77C public WeakReference(object target) : this(target, false) { } /// Initializes a new instance of the class, referencing the specified object and using the specified resurrection tracking. /// An object to track. /// Indicates when to stop tracking the object. If true, the object is tracked after finalization; if false, the object is only tracked until finalization. // Token: 0x06004138 RID: 16696 RVA: 0x000DE588 File Offset: 0x000DC788 public WeakReference(object target, bool trackResurrection) { this.isLongReference = trackResurrection; this.AllocateHandle(target); } /// Initializes a new instance of the class, using deserialized data from the specified serialization and stream objects. /// An object that holds all the data needed to serialize or deserialize the current object. /// (Reserved) Describes the source and destination of the serialized stream specified by . /// /// is null. // Token: 0x06004139 RID: 16697 RVA: 0x000DE5A0 File Offset: 0x000DC7A0 protected WeakReference(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } this.isLongReference = info.GetBoolean("TrackResurrection"); object value = info.GetValue("TrackedObject", typeof(object)); this.AllocateHandle(value); } // Token: 0x0600413A RID: 16698 RVA: 0x000DE5F4 File Offset: 0x000DC7F4 private void AllocateHandle(object target) { if (this.isLongReference) { this.gcHandle = GCHandle.Alloc(target, GCHandleType.WeakTrackResurrection); } else { this.gcHandle = GCHandle.Alloc(target, GCHandleType.Weak); } } /// Gets an indication whether the object referenced by the current object has been garbage collected. /// true if the object referenced by the current object has not been garbage collected and is still accessible; otherwise, false. /// 2 // Token: 0x17000C0A RID: 3082 // (get) Token: 0x0600413B RID: 16699 RVA: 0x000DE62C File Offset: 0x000DC82C public virtual bool IsAlive { get { return this.Target != null; } } /// Gets or sets the object (the target) referenced by the current object. /// null if the object referenced by the current object has been garbage collected; otherwise, a reference to the object referenced by the current object. /// The reference to the target object is invalid. This exception can be thrown while setting this property if the value is a null reference or if the object has been finalized during the set operation. /// 2 // Token: 0x17000C0B RID: 3083 // (get) Token: 0x0600413C RID: 16700 RVA: 0x000DE63C File Offset: 0x000DC83C // (set) Token: 0x0600413D RID: 16701 RVA: 0x000DE64C File Offset: 0x000DC84C public virtual object Target { get { return this.gcHandle.Target; } set { this.gcHandle.Target = value; } } /// Gets an indication whether the object referenced by the current object is tracked after it is finalized. /// true if the object the current object refers to is tracked after finalization; or false if the object is only tracked until finalization. /// 2 // Token: 0x17000C0C RID: 3084 // (get) Token: 0x0600413E RID: 16702 RVA: 0x000DE65C File Offset: 0x000DC85C public virtual bool TrackResurrection { get { return this.isLongReference; } } /// Discards the reference to the target represented by the current object. // Token: 0x0600413F RID: 16703 RVA: 0x000DE664 File Offset: 0x000DC864 ~WeakReference() { this.gcHandle.Free(); } /// Populates a object with all the data needed to serialize the current object. /// An object that holds all the data needed to serialize or deserialize the current object. /// (Reserved) The location where serialized data is stored and retrieved. /// /// is null. /// 2 // Token: 0x06004140 RID: 16704 RVA: 0x000DE6A4 File Offset: 0x000DC8A4 public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } info.AddValue("TrackResurrection", this.TrackResurrection); try { info.AddValue("TrackedObject", this.Target); } catch (Exception) { info.AddValue("TrackedObject", null); } } // Token: 0x04001A40 RID: 6720 private bool isLongReference; // Token: 0x04001A41 RID: 6721 private GCHandle gcHandle; } }