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.

WeakReference.cs 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. namespace Svelto.DataStructures
  9. {
  10. [Serializable]
  11. public class WeakReference<T>
  12. : WeakReference where T : class
  13. {
  14. /// <span class="code-SummaryComment"><summary></span>
  15. /// Gets or sets the object (the target) referenced by the
  16. /// current WeakReference{T} object.
  17. /// <span class="code-SummaryComment"></summary></span>
  18. public new T Target
  19. {
  20. get
  21. {
  22. return (T)base.Target;
  23. }
  24. set
  25. {
  26. base.Target = value;
  27. }
  28. }
  29. /// <span class="code-SummaryComment"><summary></span>
  30. /// Initializes a new instance of the WeakReference{T} class, referencing
  31. /// the specified object.
  32. /// <span class="code-SummaryComment"></summary></span>
  33. /// <span class="code-SummaryComment"><param name="target">The object to reference.</param></span>
  34. public WeakReference(T target)
  35. : base(target)
  36. { }
  37. /// <span class="code-SummaryComment"><summary></span>
  38. /// Initializes a new instance of the WeakReference{T} class, referencing
  39. /// the specified object and using the specified resurrection tracking.
  40. /// <span class="code-SummaryComment"></summary></span>
  41. /// <span class="code-SummaryComment"><param name="target">An object to track.</param></span>
  42. /// <span class="code-SummaryComment"><param name="trackResurrection">Indicates when to stop tracking the object. </span>
  43. /// If true, the object is tracked
  44. /// after finalization; if false, the object is only tracked
  45. /// until finalization.<span class="code-SummaryComment"></param></span>
  46. public WeakReference(T target, bool trackResurrection)
  47. : base(target, trackResurrection)
  48. { }
  49. protected WeakReference(SerializationInfo info, StreamingContext context)
  50. : base(info, context)
  51. { }
  52. }
  53. }