-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWeakReference.cs
67 lines (61 loc) · 2.98 KB
/
WeakReference.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Runtime.Serialization;
namespace MajiirKerbalLib
{
/// <summary>
/// Strongly-typed weak reference.
/// See: http://blog.somewhatabstract.com/2012/03/24/strongly-typed-weakreference/
/// </summary>
/// <typeparam name="T">The type of object being referenced.</typeparam>
internal class WeakReference<T> : WeakReference, ISerializable where T : class
{
/// <summary>
/// Initializes a new instance of the <see cref="WeakReference<T>"/> class, referencing
/// the specified object.
/// </summary>
/// <param name="target">An object to track.</param>
public WeakReference(T target)
: base(target)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="WeakReference<T>"/> class, referencing
/// the specified object and using the specified resurrection tracking.
/// </summary>
/// <param name="target">An object to track.</param>
/// <param name="trackResurrection">Indicates when to stop tracking the object. If <c>true</c>, the object is tracked
/// after finalization; if <c>false</c>, the object is only tracked until finalization..</param>
public WeakReference(T target, bool trackResurrection)
: base(target, trackResurrection)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="WeakReference<T>"/> class.
/// </summary>
/// <param name="info">An object that holds all the data needed to serialize or deserialize the current <see cref="T:System.WeakReference"/> object.</param>
/// <param name="context">(Reserved) Describes the source and destination of the serialized stream specified by <paramref name="info"/>.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="info"/> is null. </exception>
protected WeakReference(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
/// <summary>
/// Gets or sets the object (the target) referenced by the current <see cref="T:System.WeakReference"/> object.
/// </summary>
/// <value></value>
/// <returns>null if the object referenced by the current <see cref="T:System.WeakReference"/> object has been garbage collected; otherwise, a reference to the object referenced by the current <see cref="T:System.WeakReference"/> object.</returns>
/// <exception cref="T:System.InvalidOperationException">The reference to the target object is invalid. This exception can be thrown while setting this property if the value is a null reference or if the object has been finalized during the set operation.</exception>
public new T Target
{
get
{
return (T)base.Target;
}
set
{
base.Target = value;
}
}
}
}