mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-10-31 19:04:45 +00:00
acd7892436
Fixed some code analysis warnings. Dropped Extended Strongly Typed Resource Generator dependency. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4035615
52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Globalization;
|
|
using Jellyfish.Virtu.Properties;
|
|
|
|
namespace Jellyfish.Virtu.Services
|
|
{
|
|
public sealed class MachineServices : IServiceProvider
|
|
{
|
|
public void AddService(Type serviceType, MachineService serviceProvider)
|
|
{
|
|
if (serviceType == null)
|
|
{
|
|
throw new ArgumentNullException("serviceType");
|
|
}
|
|
if (_serviceProviders.ContainsKey(serviceType))
|
|
{
|
|
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.ServiceAlreadyPresent, serviceType.FullName), "serviceType");
|
|
}
|
|
if (serviceProvider == null)
|
|
{
|
|
throw new ArgumentNullException("serviceProvider");
|
|
}
|
|
if (!serviceType.IsAssignableFrom(serviceProvider.GetType()))
|
|
{
|
|
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.ServiceMustBeAssignable, serviceType.FullName, serviceProvider.GetType().FullName));
|
|
}
|
|
|
|
_serviceProviders.Add(serviceType, serviceProvider);
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
|
|
public T GetService<T>()
|
|
{
|
|
return (T)GetService(typeof(T));
|
|
}
|
|
|
|
public object GetService(Type serviceType)
|
|
{
|
|
return _serviceProviders.ContainsKey(serviceType) ? _serviceProviders[serviceType] : null;
|
|
}
|
|
|
|
public void RemoveService(Type serviceType)
|
|
{
|
|
_serviceProviders.Remove(serviceType);
|
|
}
|
|
|
|
private Dictionary<Type, MachineService> _serviceProviders = new Dictionary<Type, MachineService>();
|
|
}
|
|
}
|