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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/// <summary>
/// StrongTypes WeakReference
/// </summary>
/// <typeparam name="T">Type of the Target for which the Weakrefernce should be stored.</typeparam>
public sealed class WeakReference<T>
{
WeakReference m_Target;
/// <summary>
/// The Strong Typed Reference Target
/// </summary>
public T Target
{
get
{
T result;
result = (T)m_Target.Target;
return result;
}
}
/// <summary>
/// Gets a value indicating whether this instance is alive.
/// </summary>
/// <value><c>true</c> if this instance is alive; otherwise, <c>false</c>.</value>
public bool IsAlive
{
get
{
bool alive = false;
if (m_Target != null)
{
alive = m_Target.IsAlive;
}
return alive;
}
}
/// <summary>
/// Gets a value indicating whether [track resurrection].
/// </summary>
/// <value><c>true</c> if [track resurrection]; otherwise, <c>false</c>.</value>
public bool TrackResurrection
{
get
{
bool track = false;
if (m_Target != null)
{
track = m_Target.TrackResurrection;
}
return track;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="WeakReference<T>"/> class.
/// </summary>
/// <param name="target">The target.</param>
public WeakReference(T target)
{
Contract.Requires(target != null, "The Target should be different from null!");
this.m_Target = new WeakReference(target);
}
/// <summary>
/// Initializes a new instance of the <see cref="WeakReference<T>"/> class.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="trackResurrection">Indicates wether the object will be tracked after resurrection</param>
public WeakReference(T target, bool trackResurrection)
{
Contract.Requires(target != null, "The Target should be different from null!");
this.m_Target = new WeakReference(target,trackResurrection);
}
}
|