StringBuilderHelper is now a static class; WeakReference<T> no longer derives from WeakReference if compiled for Windows Phone 7 because this makes the Windows Phone emulator crash as soon as the WeakReference<T> is referenced - nearly identical functionality is provided with an implicit conversion operator

git-svn-id: file:///srv/devel/repo-conversion/nusu@207 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2010-11-18 10:47:09 +00:00
parent f304f8c783
commit d99137f0dd
8 changed files with 127 additions and 2 deletions

View File

@ -351,6 +351,9 @@
<DependentUpon>WeightedTransaction.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.cs" />
<Compile Include="Source\WeakReference.Phone7.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.Test.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>

View File

@ -355,6 +355,9 @@
<DependentUpon>WeightedTransaction.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.cs" />
<Compile Include="Source\WeakReference.Phone7.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.Test.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectGuid>{DFFEAB70-51B8-4714-BCA6-79B733BBC520}</ProjectGuid>
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@ -365,6 +365,9 @@
<DependentUpon>WeightedTransaction.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.cs" />
<Compile Include="Source\WeakReference.Phone7.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.Test.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>

View File

@ -386,6 +386,9 @@
<DependentUpon>WeightedTransaction.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.cs" />
<Compile Include="Source\WeakReference.Phone7.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.Test.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>

View File

@ -397,6 +397,9 @@
<DependentUpon>WeightedTransaction.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.cs" />
<Compile Include="Source\WeakReference.Phone7.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.Test.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>

View File

@ -26,7 +26,7 @@ using System.Text;
namespace Nuclex.Support {
/// <summary>Contains helper methods for the string builder class</summary>
public class StringBuilderHelper {
public static class StringBuilderHelper {
/// <summary>Predefined unicode characters for the numbers 0 to 9</summary>
private static readonly char[] numbers = new char[] {

View File

@ -0,0 +1,106 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2010 Nuclex Development Labs
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
using System;
using System.Collections.Generic;
namespace Nuclex.Support {
#if WINDOWS_PHONE
/// <summary>
/// Type-safe weak reference, referencing an object while still allowing
/// that object to be garbage collected.
/// </summary>
public class WeakReference<ReferencedType>
where ReferencedType : class {
/// <summary>
/// Initializes a new instance of the WeakReference class, referencing
/// the specified object.
/// </summary>
/// <param name="target">The object to track or null.</param>
public WeakReference(ReferencedType target) {
this.weakReference = new WeakReference(target);
}
/// <summary>
/// Initializes a new instance of the 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) {
this.weakReference = new WeakReference(target, trackResurrection);
}
/// <summary>
/// Implicitly converts a typed WeakReference into a non-typesafe WeakReference
/// </summary>
/// <param name="self">The types WeakReference that will be converted</param>
/// <returns>The non-typesafe WeakReference</returns>
public static implicit operator WeakReference(WeakReference<ReferencedType> self) {
return self.weakReference;
}
/// <summary>
/// Gets or sets the object (the target) referenced by the current WeakReference
/// object.
/// </summary>
/// <remarks>
/// Is 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 ReferencedType Target {
get { return this.weakReference.Target as ReferencedType; }
set { this.weakReference.Target = value; }
}
/// <summary>
/// whether the object referenced by the WeakReference has been garbage collected
/// </summary>
public virtual bool IsAlive {
get { return this.weakReference.IsAlive; }
}
/// <summary>
/// Whether the object referenced by the WeakReference is tracked after it is finalized
/// </summary>
public virtual bool TrackResurrection {
get { return this.weakReference.TrackResurrection; }
}
/// <summary>The non-typesafe WeakReference being wrapped</summary>
private WeakReference weakReference;
}
#endif // WINDOWS_PHONE
} // namespace Nuclex.Support

View File

@ -24,6 +24,8 @@ using System.Runtime.Serialization;
namespace Nuclex.Support {
#if !WINDOWS_PHONE
/// <summary>
/// Type-safe weak reference, referencing an object while still allowing
/// that object to be garbage collected.
@ -96,4 +98,6 @@ namespace Nuclex.Support {
}
#endif // !WINDOWS_PHONE
} // namespace Nuclex.Support