namespace System
{
[Serializable]
+ [ComVisible (true)]
public class WeakReference : ISerializable
{
//Fields
}
//Constructors
+#if NET_2_1
+ protected WeakReference ()
+ {
+ }
+#endif
public WeakReference (object target)
: this (target, false)
{
public virtual bool IsAlive {
get {
//Target property takes care of the exception
- return (Target != null);
+ return (Target != null);
}
}
public virtual object Target {
get {
- //Exception is thrown by gcHandle's Target
+ // This shouldn't throw an exception after finalization
+ // http://blogs.msdn.com/b/yunjin/archive/2005/08/31/458231.aspx
+ if (!gcHandle.IsAllocated)
+ return null;
return gcHandle.Target;
}
set