Added DisposableBase to library.

Replaced Machine.GetCards<T> with Machine.Slots.OfType<T>.
This commit is contained in:
Sean Fausett 2012-06-18 14:23:26 +12:00
parent 06b887699a
commit b24bcd767e
12 changed files with 54 additions and 30 deletions

26
Library/DisposableBase.cs Normal file
View File

@ -0,0 +1,26 @@
using System;
namespace Jellyfish.Library
{
public abstract class DisposableBase : IDisposable
{
protected DisposableBase()
{
}
~DisposableBase()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
}
}
}

View File

@ -10,14 +10,14 @@ using Microsoft.Phone.Shell;
namespace Jellyfish.Library
{
public class ApplicationBase : Application
public abstract class ApplicationBase : Application
{
public ApplicationBase() :
protected ApplicationBase() :
this(null)
{
}
public ApplicationBase(string name)
protected ApplicationBase(string name)
{
Name = name;

View File

@ -74,6 +74,9 @@
<Compile Include="..\DispatcherExtensions.cs">
<Link>DispatcherExtensions.cs</Link>
</Compile>
<Compile Include="..\DisposableBase.cs">
<Link>DisposableBase.cs</Link>
</Compile>
<Compile Include="..\FrameRateCounter.xaml.cs">
<Link>FrameRateCounter.xaml.cs</Link>
<DependentUpon>FrameRateCounter.xaml</DependentUpon>

View File

@ -68,6 +68,9 @@
<Compile Include="..\..\DispatcherExtensions.cs">
<Link>DispatcherExtensions.cs</Link>
</Compile>
<Compile Include="..\..\DisposableBase.cs">
<Link>DisposableBase.cs</Link>
</Compile>
<Compile Include="..\..\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>

View File

@ -7,16 +7,16 @@ using System.Windows.Threading;
namespace Jellyfish.Library
{
public class ApplicationBase : Application
public abstract class ApplicationBase : Application
{
[SecurityCritical]
public ApplicationBase() :
protected ApplicationBase() :
this(null)
{
}
[SecurityCritical]
public ApplicationBase(string name)
protected ApplicationBase(string name)
{
Name = name;

View File

@ -66,6 +66,9 @@
<Compile Include="..\DispatcherExtensions.cs">
<Link>DispatcherExtensions.cs</Link>
</Compile>
<Compile Include="..\DisposableBase.cs">
<Link>DisposableBase.cs</Link>
</Compile>
<Compile Include="..\FrameRateCounter.xaml.cs">
<Link>FrameRateCounter.xaml.cs</Link>
<DependentUpon>FrameRateCounter.xaml</DependentUpon>

View File

@ -9,9 +9,9 @@ using Microsoft.Xna.Framework.Input;
namespace Jellyfish.Library
{
public class GameBase : Game
public abstract class GameBase : Game
{
public GameBase(string name)
protected GameBase(string name)
{
Name = name;

View File

@ -88,6 +88,9 @@
<Compile Include="..\AssemblyCommentAttribute.cs">
<Link>AssemblyCommentAttribute.cs</Link>
</Compile>
<Compile Include="..\DisposableBase.cs">
<Link>DisposableBase.cs</Link>
</Compile>
<Compile Include="..\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>

View File

@ -103,6 +103,9 @@
<Compile Include="..\AssemblyCommentAttribute.cs">
<Link>AssemblyCommentAttribute.cs</Link>
</Compile>
<Compile Include="..\DisposableBase.cs">
<Link>DisposableBase.cs</Link>
</Compile>
<Compile Include="..\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>

View File

@ -106,6 +106,9 @@
<Compile Include="..\AssemblyCommentAttribute.cs">
<Link>AssemblyCommentAttribute.cs</Link>
</Compile>
<Compile Include="..\DisposableBase.cs">
<Link>DisposableBase.cs</Link>
</Compile>
<Compile Include="..\GCHandleHelpers.cs">
<Link>GCHandleHelpers.cs</Link>
</Compile>

View File

@ -48,11 +48,6 @@ namespace Jellyfish.Virtu
_unpauseEvent.Close();
}
public IEnumerable<T> GetCards<T>() where T : PeripheralCard
{
return Slots.Where(card => card is T).Cast<T>();
}
public void Reset()
{
foreach (var component in Components)
@ -192,7 +187,7 @@ namespace Jellyfish.Virtu
{
//_debugService = Services.GetService<DebugService>();
_storageService = Services.GetService<StorageService>();
_bootDiskII = GetCards<DiskIIController>().Last();
_bootDiskII = Slots.OfType<DiskIIController>().Last();
Initialize();
Reset();

View File

@ -3,7 +3,7 @@ using Jellyfish.Library;
namespace Jellyfish.Virtu.Services
{
public abstract class MachineService : IDisposable
public abstract class MachineService : DisposableBase
{
protected MachineService(Machine machine)
{
@ -12,21 +12,6 @@ namespace Jellyfish.Virtu.Services
_debugService = new Lazy<DebugService>(() => Machine.Services.GetService<DebugService>());
}
~MachineService()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
}
protected Machine Machine { get; private set; }
protected DebugService DebugService { get { return _debugService.Value; } }