IEmulatorServiceProvider and BasicServiceProvider - restrict to IEmulatorServices

This commit is contained in:
adelikat 2015-01-23 20:55:13 +00:00
parent 773826049f
commit 7cca0be2e7
2 changed files with 11 additions and 4 deletions

View File

@ -21,7 +21,11 @@ namespace BizHawk.Emulation.Common
Type coreType = core.GetType();
foreach (Type service in coreType.GetInterfaces().Where(t => t != typeof(IEmulatorService)))
var services = coreType.GetInterfaces()
.Where(t => typeof(IEmulatorService).IsAssignableFrom(t))
.Where(t => t != typeof(IEmulatorService));
foreach (Type service in services)
{
Services.Add(service, core);
}
@ -40,7 +44,8 @@ namespace BizHawk.Emulation.Common
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="provider"></param>
public void Register<T>(T provider)
public void Register<T>(T provider)
where T : IEmulatorService
{
if (provider == null)
throw new ArgumentNullException("provider");
@ -48,6 +53,7 @@ namespace BizHawk.Emulation.Common
}
public T GetService<T>()
where T : IEmulatorService
{
return (T)GetService(typeof(T));
}
@ -62,6 +68,7 @@ namespace BizHawk.Emulation.Common
}
public bool HasService<T>()
where T : IEmulatorService
{
return HasService(typeof(T));
}

View File

@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Common
/// <summary>
/// Returns whether or not T is available
/// </summary>
bool HasService<T>();
bool HasService<T>() where T : IEmulatorService;
/// <summary>
/// Returns whether or not t is available
@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Common
/// Returns an instance of T if T is available
/// Else returns null
/// </summary>
T GetService<T>();
T GetService<T>() where T : IEmulatorService;
/// <summary>
/// Returns an instance of t if t is available