From 7cca0be2e7f7456a6a6301a7dec4e0593ac8c7a4 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 23 Jan 2015 20:55:13 +0000 Subject: [PATCH] IEmulatorServiceProvider and BasicServiceProvider - restrict to IEmulatorServices --- .../Base Implementations/BasicServiceProvider.cs | 11 +++++++++-- .../Interfaces/IEmulatorServiceProvider.cs | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs index 2a7fa0edf1..73a9bd9198 100644 --- a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs +++ b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs @@ -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 /// /// /// - public void Register(T provider) + public void Register(T provider) + where T : IEmulatorService { if (provider == null) throw new ArgumentNullException("provider"); @@ -48,6 +53,7 @@ namespace BizHawk.Emulation.Common } public T GetService() + where T : IEmulatorService { return (T)GetService(typeof(T)); } @@ -62,6 +68,7 @@ namespace BizHawk.Emulation.Common } public bool HasService() + where T : IEmulatorService { return HasService(typeof(T)); } diff --git a/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs b/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs index 14b48d1d6d..1ef4300d67 100644 --- a/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs +++ b/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs @@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Common /// /// Returns whether or not T is available /// - bool HasService(); + bool HasService() where T : IEmulatorService; /// /// 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 /// - T GetService(); + T GetService() where T : IEmulatorService; /// /// Returns an instance of t if t is available