Пример #1
0
 /// <summary>
 /// Remove a reference to the specified object (if there is a live reference).
 /// </summary>
 /// <param name="collection">The collection to remove the reference from.</param>
 /// <param name="id">The id of the object to remove references to.</param>
 public static void RemoveReferenceTo(this WeakReferenceCollection collection, DisposableObjectId id)
 {
     foreach (WeakReferenceOf <IManagedDisposableObject> weakreference in collection)
     {
         if (weakreference.Id.Equals(id))
         {
             // We expect only one reference to the object
             collection.Remove(weakreference);
             Debug.Assert(collection.Where(x => x.Id.Equals(id)).Count() == 0, "Expected only one reference");
             break;
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the WeakReferenceOf struct.
 /// </summary>
 /// <param name="target">The object to hold a reference to.</param>
 public WeakReferenceOf(T target)
 {
     this.weakReference = new WeakReference(target, true);
     this.id            = target.Id;
 }