Skip to content

Utilities TableUtils

Adam Bajguz edited this page Aug 18, 2020 · 1 revision

Typin comes with a simple utility for writing tables to the console. It can display both ungrouped and single-level grouped collections. Its configuration uses expressions to specfiy columns and column values transformations to string.

TableUtils.Write(console,
                 _cliContext.Services.OrderBy(x => x.Lifetime)
                                     .ThenBy(x => x.ServiceType.Name)
                                     .ThenBy(x => x.ImplementationType?.Name)
                                     .GroupBy(x => x.Lifetime),
                 new string[] { "Service type", "Implementation type", "F", "I", "Lifetime" },
                 footnotes:
                 "  F - whether implementation factory is used\n" +
                 "  I - whether implementation instanace is used",
                 x => x.ServiceType.Name,
                 x => x.ImplementationType == null ? string.Empty : x.ImplementationType.Name,
                 x => x.ImplementationFactory == null ? string.Empty : "+",
                 x => x.ImplementationInstance == null ? string.Empty : "+",
                 x => x.Lifetime.ToString());
=============================================================================
 Service type               | Implementation type        | F | I | Lifetime
=============================================================================
-----------------------------------------------------------------------------
                               Singleton (9)
-----------------------------------------------------------------------------
 ApplicationConfiguration   |                            | + |   | Singleton
 ApplicationMetadata        |                            | + |   | Singleton
 ExecutionTimingMiddleware  | ExecutionTimingMiddleware  |   |   | Singleton
 ExitCodeMiddleware         | ExitCodeMiddleware         |   |   | Singleton
 ICliContext                |                            | + |   | Singleton
 ICommandMiddleware         | ExecutionTimingMiddleware  |   |   | Singleton
 ICommandMiddleware         | ExitCodeMiddleware         |   |   | Singleton
 IConsole                   |                            | + |   | Singleton
 LibraryService             | LibraryService             |   |   | Singleton
-----------------------------------------------------------------------------
                               Transient (14)
-----------------------------------------------------------------------------
 BookAddCommand             | BookAddCommand             |   |   | Transient
 BookCommand                | BookCommand                |   |   | Transient
 BookListCommand            | BookListCommand            |   |   | Transient
 BookRemoveCommand          | BookRemoveCommand          |   |   | Transient
 DefaultDirective           | DefaultDirective           |   |   | Transient
 ICommand                   | BookAddCommand             |   |   | Transient
 ICommand                   | BookCommand                |   |   | Transient
 ICommand                   | BookListCommand            |   |   | Transient
 ICommand                   | BookRemoveCommand          |   |   | Transient
 ICommand                   | ServicesCommand            |   |   | Transient
 IDirective                 | DefaultDirective           |   |   | Transient
 IDirective                 | PreviewDirective           |   |   | Transient
 PreviewDirective           | PreviewDirective           |   |   | Transient
 ServicesCommand            | ServicesCommand            |   |   | Transient
=============================================================================
  F - whether implementation factory is used
  I - whether implementation instanace is used
=============================================================================
Clone this wiki locally