reate…

I think Microsoft forgot to implement a generic WeakReference. Well here it is - it still requires a type cast but I think it's a lot nicer to use it strongly typed.

internal sealed class WeakReference { WeakReference weakRef; [DebuggerStepThrough] public WeakReference(T target) { weakRef = new WeakReference(target); } [DebuggerStepThrough] public WeakReference(object target, bool trackResurrection) { weakRef = new WeakReference(target, trackResurrection); } public bool IsAlive { [DebuggerStepThrough] get { return weakRef.IsAlive; } } public T Target { [DebuggerStepThrough] get { return (T)weakRef.Target; } [DebuggerStepThrough] set { weakRef.Target = value; } } public bool TrackResurrection { [DebuggerStepThrough] get { return weakRef.TrackResurrection; } } }

Google
m@kli.dk @klinkby RSS feed  GitHub