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
This commit is contained in:
Markus Ewald 2007-06-18 21:25:16 +00:00
parent 991fab9721
commit 6d79fe3ebc
3 changed files with 77 additions and 1 deletions

View File

@ -220,6 +220,10 @@
<XNAUseContentPipeline>false</XNAUseContentPipeline> <XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>WeightedProgressionWrapperCollection</Name> <Name>WeightedProgressionWrapperCollection</Name>
</Compile> </Compile>
<Compile Include="Source\WeakReference.cs">
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>WeakReference</Name>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Nuclex.Support.txt"> <Content Include="Nuclex.Support.txt">

View File

@ -34,7 +34,7 @@ namespace Nuclex.Support.Packing {
/// The algorithm always places rectangles as low as possible in the 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, /// 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 /// 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.
/// </para> /// </para>
/// <para> /// <para>
/// To quickly discover these locations, the packer uses a sophisticated /// To quickly discover these locations, the packer uses a sophisticated

72
Source/WeakReference.cs Normal file
View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Nuclex.Support {
/// <summary>
/// Represents a weak reference, which references an object while still allowing
/// that object to be garbage collected.
/// </summary>
public class WeakReference<ReferencedType> : WeakReference
where ReferencedType : class {
/// <summary>
/// Initializes a new instance of the System.WeakReference class, referencing
/// the specified object.
/// </summary>
/// <param name="target">The object to track or null.</param>
public WeakReference(ReferencedType target)
: base(target) { }
/// <summary>
/// Initializes a new instance of the System.WeakReference class, referencing
/// 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) { }
/// <summary>
/// Initializes a new instance of the System.WeakReference class, using deserialized
/// 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) { }
/// <summary>
/// Gets or sets the object (the target) referenced by the current System.WeakReference
/// object.
/// </summary>
/// <remarks>
/// 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.
/// </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