39 lines
1.8 KiB
C#
39 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Unosquare.Swan.Exceptions {
|
|
/// <summary>
|
|
/// Generic Constraint Registration Exception.
|
|
/// </summary>
|
|
/// <seealso cref="Exception" />
|
|
public class DependencyContainerRegistrationException : Exception {
|
|
private const String ConvertErrorText = "Cannot convert current registration of {0} to {1}";
|
|
private const String RegisterErrorText =
|
|
"Cannot register type {0} - abstract classes or interfaces are not valid implementation types for {1}.";
|
|
private const String ErrorText = "Duplicate implementation of type {0} found ({1}).";
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="DependencyContainerRegistrationException"/> class.
|
|
/// </summary>
|
|
/// <param name="registerType">Type of the register.</param>
|
|
/// <param name="types">The types.</param>
|
|
public DependencyContainerRegistrationException(Type registerType, IEnumerable<Type> types)
|
|
: base(String.Format(ErrorText, registerType, GetTypesString(types))) {
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="DependencyContainerRegistrationException" /> class.
|
|
/// </summary>
|
|
/// <param name="type">The type.</param>
|
|
/// <param name="method">The method.</param>
|
|
/// <param name="isTypeFactory">if set to <c>true</c> [is type factory].</param>
|
|
public DependencyContainerRegistrationException(Type type, String method, Boolean isTypeFactory = false)
|
|
: base(isTypeFactory
|
|
? String.Format(RegisterErrorText, type.FullName, method)
|
|
: String.Format(ConvertErrorText, type.FullName, method)) {
|
|
}
|
|
|
|
private static String GetTypesString(IEnumerable<Type> types) => String.Join(",", types.Select(type => type.FullName));
|
|
}
|
|
} |