DuplicateCodeException.cs 669 B

123456789101112131415161718192021222324
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace InABox.Core
  5. {
  6. public class DuplicateCodeException : Exception
  7. {
  8. private readonly Dictionary<string, object> _duplicates;
  9. private readonly Type _type;
  10. public DuplicateCodeException(Type type, Dictionary<string, object> duplicates)
  11. {
  12. _type = type;
  13. _duplicates = duplicates;
  14. }
  15. public override string Message => string.Format("A {0} with {1} already exists!",
  16. _type.Name,
  17. string.Join(" and ", _duplicates.Select(x => string.Format("a {0} of ({1})", x.Key, x.Value)))
  18. );
  19. }
  20. }