Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.1KB

  1. using System;
  2. using System.Runtime.Serialization;
  3. /// <span class="code-SummaryComment"><summary></span>
  4. /// Represents a weak reference, which references an object while still allowing
  5. /// that object to be reclaimed by garbage collection.
  6. /// <span class="code-SummaryComment"></summary></span>
  7. /// <span class="code-SummaryComment"><typeparam name="T">The type of the object that is referenced.</typeparam></span>
  8. [Serializable]
  9. public class WeakReference<T>
  10. : WeakReference where T : class
  11. {
  12. /// <span class="code-SummaryComment"><summary></span>
  13. /// Initializes a new instance of the WeakReference{T} class, referencing
  14. /// the specified object.
  15. /// <span class="code-SummaryComment"></summary></span>
  16. /// <span class="code-SummaryComment"><param name="target">The object to reference.</param></span>
  17. public WeakReference(T target)
  18. : base(target)
  19. { }
  20. /// <span class="code-SummaryComment"><summary></span>
  21. /// Initializes a new instance of the WeakReference{T} class, referencing
  22. /// the specified object and using the specified resurrection tracking.
  23. /// <span class="code-SummaryComment"></summary></span>
  24. /// <span class="code-SummaryComment"><param name="target">An object to track.</param></span>
  25. /// <span class="code-SummaryComment"><param name="trackResurrection">Indicates when to stop tracking the object. </span>
  26. /// If true, the object is tracked
  27. /// after finalization; if false, the object is only tracked
  28. /// until finalization.<span class="code-SummaryComment"></param></span>
  29. public WeakReference(T target, bool trackResurrection)
  30. : base(target, trackResurrection)
  31. { }
  32. protected WeakReference(SerializationInfo info, StreamingContext context)
  33. : base(info, context)
  34. { }
  35. /// <span class="code-SummaryComment"><summary></span>
  36. /// Gets or sets the object (the target) referenced by the
  37. /// current WeakReference{T} object.
  38. /// <span class="code-SummaryComment"></summary></span>
  39. public new T Target
  40. {
  41. get
  42. {
  43. return (T)base.Target;
  44. }
  45. set
  46. {
  47. base.Target = value;
  48. }
  49. }
  50. }