using System; using System.Runtime.Serialization; namespace Chernobyl { /// /// A generic version of the class. This class /// is used to refer to an object while still allowing that object to be /// garbage collected. /// /// The type of the object being garbage collected. This /// type must be a reference type. [Serializable] public class WeakReference : WeakReference where T : class { /// /// Initializes a new instance of the class. /// /// The object to track or null. public WeakReference(T target) : base(target) { } /// /// Initializes a new instance of the WeakReference{T} 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. public WeakReference(T target, bool trackResurrection) : base(target, trackResurrection) { } /// /// 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 this object. /// Describes the source and destination of the /// serialized stream specified by info. protected WeakReference(SerializationInfo info, StreamingContext context) : base(info, context) { } /// /// The object being referenced or null if the object has been garbage /// collected. /// /// Performance Warning: Note that, the target will need to be casted /// from the property to ensure it is /// of the proper type. Therefore, call this method sparingly. If you /// need to check if an object has been garbage collected, use the /// property instead. /// public new T Target { get { return (T)base.Target; } set { base.Target = value; } } } }