src/toofz.ExceptionRenderer/ExceptionRenderer.cs
/// <summary>
/// Renders an object of type <see cref="Exception"/> similar to how Visual Studio Exception Assistant 
/// renders it.
/// </summary>
/// <param name="rendererMap">Not used.</param>
/// <param name="exception">The exception.</param>
/// <param name="writer">The writer.</param>
Renders an object of type  similar to how Visual Studio Exception Assistant
renders it.
Renders an object of type similar to how Visual Studio Exception Assistant renders it .
public void RenderObject(RendererMap rendererMap, object exception, TextWriter writer)
        {
            var ex = (Exception)exception;
            var type = ex.GetType();
            var indentedWriter = writer as IndentedTextWriter;
            if (indentedWriter == null)
            {
                indentedWriter = new IndentedTextWriter(writer, "  ");
            }
            indentedWriter.Write($"[{type}] {ex.Message}");
            indentedWriter.Indent++;
            foreach (var property in type.GetProperties().OrderBy(x => x.Name))
            {
                var name = property.Name;
                switch (name)
                {
                    case nameof(Exception.Data):
                    case nameof(Exception.TargetSite):
                    case nameof(Exception.Message):
                    case nameof(Exception.StackTrace):
                    case nameof(Exception.InnerException):
                        break;
                    default:
                        var value = property.GetValue(ex);
                        if ((name == nameof(Exception.HResult)) ||
                            (ex is ExternalException && name == nameof(ExternalException.ErrorCode)))
                        {
                            indentedWriter.WriteLineStart($"{name}=0x{value:X}");
                        }
                        else if (value != null)
                        {
                            indentedWriter.WriteLineStart($"{name}=");
                            rendererMap.FindAndRender(value, indentedWriter);
                        }
                        break;
                }
            }
            RenderStackTrace(ex.StackTrace, indentedWriter);
            var innerException = ex.InnerException;
            if (innerException != null)
            {
                indentedWriter.WriteLineStart($"{nameof(Exception.InnerException)}: ");
                RenderObject(rendererMap, innerException, indentedWriter);
            }
            indentedWriter.Indent--;
        }
public void RenderObject ( RendererMap rendererMap , object exception , TextWriter writer ) { var ex = ( Exception ) exception ; var type = ex . GetType ( ) ; var indentedWriter = writer as IndentedTextWriter ; if ( indentedWriter == null ) { indentedWriter = new IndentedTextWriter ( writer , " " ) ; } indentedWriter . Write ( $" [ { type } ]  { ex . Message } " ) ; indentedWriter . Indent ++ ; foreach ( var property in type . GetProperties ( ) . OrderBy ( x => x . Name ) ) { var name = property . Name ; switch ( name ) { case nameof ( Exception . Data ) : case nameof ( Exception . TargetSite ) : case nameof ( Exception . Message ) : case nameof ( Exception . StackTrace ) : case nameof ( Exception . InnerException ) : break ; default : var value = property . GetValue ( ex ) ; if ( ( name == nameof ( Exception . HResult ) ) || ( ex is ExternalException && name == nameof ( ExternalException . ErrorCode ) ) ) { indentedWriter . WriteLineStart ( $" { name } =0x { value : } " ) ; } else if ( value != null ) { indentedWriter . WriteLineStart ( $" { name } = " ) ; rendererMap . FindAndRender ( value , indentedWriter ) ; } break ; } } RenderStackTrace ( ex . StackTrace , indentedWriter ) ; var innerException = ex . InnerException ; if ( innerException != null ) { indentedWriter . WriteLineStart ( $" { nameof ( Exception . InnerException ) } :  " ) ; RenderObject ( rendererMap , innerException , indentedWriter ) ; } indentedWriter . Indent -- ; }
Renders an object of type  similar to how Visual Studio Exception Assistant
renders it.
Renders an object of type similar to how Visual Studio Exception Assistant renders it .
// Ignored properties // Special case properties // Calling RendererMap.FindAndRender(object obj, TextWriter writer) ends up using the default Exception renderer // instead of this one ¯\_(ツ)_/¯
rendererMap
RendererMap
None
exception
object
None
writer
TextWriter
None