#region CPL License /* Nuclex Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion using System; using System.Collections.Generic; namespace Nuclex.Support { #if WINDOWS_PHONE /// /// Type-safe weak reference, referencing an object while still allowing /// that object to be garbage collected. /// public class WeakReference where ReferencedType : class { /// /// Initializes a new instance of the WeakReference class, referencing /// the specified object. /// /// The object to track or null. public WeakReference(ReferencedType target) { this.weakReference = new WeakReference(target); } /// /// Initializes a new instance of the WeakReference class, referencing /// the specified object optionally using 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(ReferencedType target, bool trackResurrection) { this.weakReference = new WeakReference(target, trackResurrection); } /// /// Implicitly converts a typed WeakReference into a non-typesafe WeakReference /// /// The types WeakReference that will be converted /// The non-typesafe WeakReference public static implicit operator WeakReference(WeakReference self) { return self.weakReference; } /// /// Gets or sets the object (the target) referenced by the current WeakReference /// object. /// /// /// Is null if the object referenced by the current System.WeakReference object /// has been garbage collected; otherwise, a reference to the object referenced /// by the current System.WeakReference object. /// /// /// The reference to the target object is invalid. This can occur if the current /// System.WeakReference object has been finalized /// public ReferencedType Target { get { return this.weakReference.Target as ReferencedType; } set { this.weakReference.Target = value; } } /// /// whether the object referenced by the WeakReference has been garbage collected /// public virtual bool IsAlive { get { return this.weakReference.IsAlive; } } /// /// Whether the object referenced by the WeakReference is tracked after it is finalized /// public virtual bool TrackResurrection { get { return this.weakReference.TrackResurrection; } } /// The non-typesafe WeakReference being wrapped private WeakReference weakReference; } #endif // WINDOWS_PHONE } // namespace Nuclex.Support