#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2009 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.Ninject.Xna {
/// Contains extension methods for the service provider
public static class ServiceProviderExtensions {
///
/// Looks up the requested service, throwing an exception if it isn't found
///
/// Type of service that will be looked up
///
/// The service provider that will be searched for the specified service
///
/// The request service
///
/// Thrown if the requested service does not exist
///
public static ServiceType GetService(
this IServiceProvider serviceProvider
) {
return (ServiceType)serviceProvider.GetService(typeof(ServiceType));
}
/// Tries to look up the specified service
/// Type of service that will be looked up
///
/// The service provider that will be searched for the specified service
///
///
/// Output parameter that will be receive the service if it was looked
/// up successfully
///
/// True if the requested service was found, false otherwise
public static bool TryGetService(
this IServiceProvider serviceProvider, out ServiceType service
) {
object serviceAsObject = serviceProvider.GetService(typeof(ServiceType));
if (serviceAsObject == null) {
service = default(ServiceType);
return false;
} else {
service = (ServiceType)serviceAsObject;
return true;
}
}
}
} // namespace Nuclex.Ninject.Xna