Exemplo n.º 1
0
 /// <summary>
 /// If <paramref name="service"/> doesn't implement <typeparamref name="T"/>, an exception is thrown.
 /// </summary>
 /// <param name="service">The service that must implement <typeparamref name="T"/>.</param>
 /// <typeparam name="T">The type that <paramref name="service"/> must implement.</typeparam>
 /// <returns></returns>
 /// <exception cref="FulcrumNotImplementedException">Thrown if <paramref name="service"/> doesn't implement <typeparamref name="T"/>.</exception>
 public static T GetImplementationOrThrow <T>(ICrudable service) where T : ICrudable
 {
     if (service is T implemented)
     {
         return(implemented);
     }
     throw new FulcrumNotImplementedException($"The service {service.GetType()} does not implement {typeof(T).Name}");
 }
Exemplo n.º 2
0
 /// <summary>
 /// If <paramref name="service"/> doesn't implement <typeparamref name="T"/>, an exception is thrown.
 /// </summary>
 /// <param name="service">The service that must implement <typeparamref name="T"/>.</param>
 /// <typeparam name="T">The type that <paramref name="service"/> must implement.</typeparam>
 /// <returns></returns>
 /// <exception cref="FulcrumNotImplementedException">Thrown if <paramref name="service"/> doesn't implement <typeparamref name="T"/>.</exception>
 public static T GetImplementationOrThrow <T>(ICrudable service) where T : ICrudable
 {
     InternalContract.RequireNotNull(service, nameof(service));
     if (service is T implemented)
     {
         return(implemented);
     }
     throw new FulcrumNotImplementedException(
               $"The service {service.GetType()} does not implement {typeof(T).Name}");
 }