Generische Ableitung der WeakReference
/// <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);
}
}
3 Kommentare zum Snippet