2007-07-01 19:27:40 +00:00
|
|
|
#region CPL License
|
|
|
|
/*
|
|
|
|
Nuclex Framework
|
2009-01-07 19:05:29 +00:00
|
|
|
Copyright (C) 2002-2009 Nuclex Development Labs
|
2007-07-01 19:27:40 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the IBM Common Public License as
|
|
|
|
published by the IBM Corporation; either version 1.0 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
IBM Common Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the IBM Common Public
|
|
|
|
License along with this library
|
|
|
|
*/
|
|
|
|
#endregion
|
2007-07-24 20:15:19 +00:00
|
|
|
|
2007-06-18 21:25:16 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
|
|
|
namespace Nuclex.Support {
|
|
|
|
|
|
|
|
/// <summary>
|
2008-07-17 20:51:35 +00:00
|
|
|
/// Type-safe weak reference, referencing an object while still allowing
|
2007-06-18 21:25:16 +00:00
|
|
|
/// that object to be garbage collected.
|
|
|
|
/// </summary>
|
2008-11-26 19:15:36 +00:00
|
|
|
[Serializable]
|
2007-06-18 21:25:16 +00:00
|
|
|
public class WeakReference<ReferencedType> : WeakReference
|
|
|
|
where ReferencedType : class {
|
|
|
|
|
|
|
|
/// <summary>
|
2009-01-08 20:14:14 +00:00
|
|
|
/// Initializes a new instance of the WeakReference class, referencing
|
2007-06-18 21:25:16 +00:00
|
|
|
/// the specified object.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="target">The object to track or null.</param>
|
|
|
|
public WeakReference(ReferencedType target)
|
|
|
|
: base(target) { }
|
|
|
|
|
|
|
|
/// <summary>
|
2009-01-08 20:14:14 +00:00
|
|
|
/// Initializes a new instance of the WeakReference class, referencing
|
2007-06-18 21:25:16 +00:00
|
|
|
/// the specified object optionally using resurrection tracking.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="target">An object to track.</param>
|
|
|
|
/// <param name="trackResurrection">
|
|
|
|
/// Indicates when to stop tracking the object. If true, the object is tracked
|
|
|
|
/// after finalization; if false, the object is only tracked until finalization.
|
|
|
|
/// </param>
|
|
|
|
public WeakReference(ReferencedType target, bool trackResurrection)
|
|
|
|
: base(target, trackResurrection) { }
|
|
|
|
|
2009-01-13 18:50:52 +00:00
|
|
|
#if !COMPACTFRAMEWORK
|
|
|
|
|
2007-06-18 21:25:16 +00:00
|
|
|
/// <summary>
|
2009-01-08 20:14:14 +00:00
|
|
|
/// Initializes a new instance of the WeakReference class, using deserialized
|
2007-06-18 21:25:16 +00:00
|
|
|
/// data from the specified serialization and stream objects.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info">
|
|
|
|
/// An object that holds all the data needed to serialize or deserialize the
|
|
|
|
/// current System.WeakReference object.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="context">
|
|
|
|
/// (Reserved) Describes the source and destination of the serialized stream
|
|
|
|
/// specified by info.
|
|
|
|
/// </param>
|
|
|
|
/// <exception cref="System.ArgumentNullException">
|
|
|
|
/// The info parameter is null.
|
|
|
|
/// </exception>
|
|
|
|
protected WeakReference(SerializationInfo info, StreamingContext context)
|
|
|
|
: base(info, context) { }
|
|
|
|
|
2009-01-13 18:50:52 +00:00
|
|
|
#endif // !COMPACTFRAMEWORK
|
|
|
|
|
2007-06-18 21:25:16 +00:00
|
|
|
/// <summary>
|
2009-01-08 20:14:14 +00:00
|
|
|
/// Gets or sets the object (the target) referenced by the current WeakReference
|
2007-06-18 21:25:16 +00:00
|
|
|
/// object.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
2008-08-01 20:55:43 +00:00
|
|
|
/// Is null if the object referenced by the current System.WeakReference object
|
2007-06-18 21:25:16 +00:00
|
|
|
/// has been garbage collected; otherwise, a reference to the object referenced
|
|
|
|
/// by the current System.WeakReference object.
|
|
|
|
/// </remarks>
|
|
|
|
/// <exception cref="System.InvalidOperationException">
|
|
|
|
/// The reference to the target object is invalid. This can occur if the current
|
|
|
|
/// System.WeakReference object has been finalized
|
|
|
|
/// </exception>
|
|
|
|
public new ReferencedType Target {
|
|
|
|
get { return (base.Target as ReferencedType); }
|
|
|
|
set { base.Target = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Nuclex.Support
|