From 6d79fe3ebcdc5688af52f1b0518558ebe2e86cc8 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Mon, 18 Jun 2007 21:25:16 +0000 Subject: [PATCH] Added new generic WeakReference class for typesafe weak reference usage git-svn-id: file:///srv/devel/repo-conversion/nusu@30 d2e56fa2-650e-0410-a79f-9358c0239efd --- Nuclex.Support (PC).csproj | 4 ++ Source/Packing/CygonRectanglePacker.cs | 2 +- Source/WeakReference.cs | 72 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Source/WeakReference.cs diff --git a/Nuclex.Support (PC).csproj b/Nuclex.Support (PC).csproj index 5b66e65..5ac35d5 100644 --- a/Nuclex.Support (PC).csproj +++ b/Nuclex.Support (PC).csproj @@ -220,6 +220,10 @@ false WeightedProgressionWrapperCollection + + false + WeakReference + diff --git a/Source/Packing/CygonRectanglePacker.cs b/Source/Packing/CygonRectanglePacker.cs index c05d43b..5307908 100644 --- a/Source/Packing/CygonRectanglePacker.cs +++ b/Source/Packing/CygonRectanglePacker.cs @@ -34,7 +34,7 @@ namespace Nuclex.Support.Packing { /// The algorithm always places rectangles as low as possible in the packing /// area. So, for any new rectangle that is to be added into the packing area, /// the packer has to determine the X coordinate at which the rectangle can have - /// lowest overall height without overlapping any other rectangles. + /// the lowest overall height without intersecting any other rectangles. /// /// /// To quickly discover these locations, the packer uses a sophisticated diff --git a/Source/WeakReference.cs b/Source/WeakReference.cs new file mode 100644 index 0000000..7adbbc9 --- /dev/null +++ b/Source/WeakReference.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace Nuclex.Support { + + /// + /// Represents a weak reference, which references an object while still allowing + /// that object to be garbage collected. + /// + public class WeakReference : WeakReference + where ReferencedType : class { + + /// + /// Initializes a new instance of the System.WeakReference class, referencing + /// the specified object. + /// + /// The object to track or null. + public WeakReference(ReferencedType target) + : base(target) { } + + /// + /// Initializes a new instance of the System.WeakReference class, referencing + /// the specified object optionally using resurrection tracking. + /// + /// An object to track. + /// + /// Indicates when to stop tracking the object. If true, the object is tracked + /// after finalization; if false, the object is only tracked until finalization. + /// + public WeakReference(ReferencedType target, bool trackResurrection) + : base(target, trackResurrection) { } + + /// + /// Initializes a new instance of the System.WeakReference class, using deserialized + /// data from the specified serialization and stream objects. + /// + /// + /// An object that holds all the data needed to serialize or deserialize the + /// current System.WeakReference object. + /// + /// + /// (Reserved) Describes the source and destination of the serialized stream + /// specified by info. + /// + /// + /// The info parameter is null. + /// + protected WeakReference(SerializationInfo info, StreamingContext context) + : base(info, context) { } + + /// + /// Gets or sets the object (the target) referenced by the current System.WeakReference + /// object. + /// + /// + /// null if the object referenced by the current System.WeakReference object + /// has been garbage collected; otherwise, a reference to the object referenced + /// by the current System.WeakReference object. + /// + /// + /// The reference to the target object is invalid. This can occur if the current + /// System.WeakReference object has been finalized + /// + public new ReferencedType Target { + get { return (base.Target as ReferencedType); } + set { base.Target = value; } + } + + } + +} // namespace Nuclex.Support