18 using System.Reflection;
20 using System.Collections.Generic;
29 private readonly List<IExceptionInterpreter> _interpreters;
34 public static readonly Lazy<StackExceptionInterpreter>
Instance =
new Lazy<StackExceptionInterpreter>(
48 _interpreters = interpreters.OrderBy(x => x.Order).ToList();
54 public IEnumerable<IExceptionInterpreter>
Interpreters => _interpreters;
63 return _interpreters.Any(interpreter => interpreter.CanInterpret(exception));
77 if (exception ==
null)
82 foreach (var interpreter
in _interpreters)
86 if (interpreter.CanInterpret(exception))
89 return interpreter.Interpret(exception, innerInterpreter ??
this);
108 return string.Join(
" ", InnersAndSelf(exception).Select(e => e.Message));
119 from assembly in assemblies.Where(x =>
120 (!x.FullName?.StartsWith(
"System.", StringComparison.InvariantCultureIgnoreCase) ??
false)
121 && (!x.FullName?.StartsWith(
"Microsoft.", StringComparison.InvariantCultureIgnoreCase) ??
false))
122 from type in assembly.GetTypes()
124 where type.IsPublic && !type.IsAbstract
128 where type.FullName !=
null && !type.FullName.StartsWith(
"Castle.Proxies.ObjectProxy", StringComparison.InvariantCultureIgnoreCase)
130 where type.GetConstructor(
new Type[0]) !=
null
132 orderby type.FullName
137 foreach (var interpreter
in stackExceptionInterpreter.Interpreters)
142 return stackExceptionInterpreter;
145 private IEnumerable<Exception> InnersAndSelf(Exception exception)
147 yield
return exception;
148 while (exception.InnerException !=
null)
150 exception = exception.InnerException;
151 yield
return exception;