Beispiel #1
0
 public static bool UnregisterTranslator(Type exceptionType, IExceptionInfoTranslator parser)
 {
     exceptionType
     .EnsureNotNull(nameof(exceptionType))
     .EnsureOfType(typeof(Exception));
     parser.EnsureNotNull(nameof(parser));
     //
     return
         (__SpinLock
          .Invoke(() => __RegisteredTranslatorsRepository.Remove(exceptionType)));
 }
Beispiel #2
0
 // TODO: Put exception messages into the resources.
 //
 public static void RegisterTranslator(Type exceptionType, IExceptionInfoTranslator parser)
 {
     exceptionType
     .EnsureNotNull(nameof(exceptionType))
     .EnsureCompatible(typeof(Exception));
     parser.EnsureNotNull(nameof(parser));
     //
     __SpinLock
     .Invoke(
         () => {
         if (__RegisteredTranslatorsRepository.ContainsKey(exceptionType))
         {
             __RegisteredTranslatorsRepository[exceptionType] = parser;
         }
         else if (__RegisteredTranslatorsRepository.Count >= MaxAllowedCountOfRegisteredTranslators)
         {
             throw new InvalidOperationException("It is impossible to register an exception info parser. The count of registered parsers has reached the max. allowed limit.");
         }
         else
         {
             __RegisteredTranslatorsRepository.Add(exceptionType, parser);
         }
     });
 }