DotNetToolbox.ObjectDumper 8.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNetToolbox.ObjectDumper --version 8.0.3                
NuGet\Install-Package DotNetToolbox.ObjectDumper -Version 8.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetToolbox.ObjectDumper" Version="8.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetToolbox.ObjectDumper --version 8.0.3                
#r "nuget: DotNetToolbox.ObjectDumper, 8.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotNetToolbox.ObjectDumper as a Cake Addin
#addin nuget:?package=DotNetToolbox.ObjectDumper&version=8.0.3

// Install DotNetToolbox.ObjectDumper as a Cake Tool
#tool nuget:?package=DotNetToolbox.ObjectDumper&version=8.0.3                

Object Dumper (DotNetToolbox.ObjectDumper)

Introduction

DotNetToolbox.ObjectDumper is a powerful .NET 8 library for converting objects into a human-readable string representations. It provides customizable formatting options, including indentation, maximum depth control, and the ability to specify custom formatters for specific types. This library is particularly useful for logging, debugging, and serialization scenarios where a visual representation of an object is needed.

Table of Contents

  1. Installation
  2. Dependencies
  3. Key Features
  4. Extension Methods
  5. Object Dumping
  6. JSON Object Dumping
  7. Customization

Installation

The DotNet Toolbox Object Dumper is available as a NuGet package. To install it, run the following command in the Package Manager Console:

PM> Install-Package DotNetToolbox.ObjectDumper

Dependencies

  • .NET 8

Extension Methods

The library extends any object with Dump and DumpAsJson methods, allowing any object to be dumped easily without requiring manual instantiation of dumper objects.

Examples:
  1. Dumping an object using default options:

    var person = new Person { Name = "John Doe", Age = 30 };
    Console.WriteLine(person.Dump());
    
  2. Customizing the dump output:

    Console.WriteLine(person.Dump(options => {
        options.IndentSize = 2;
        options.UseTabs = true;
        options.UseFullNames = true;
    });
    
  3. Dumping an object as JSON:

    Console.WriteLine(person.DumpAsJson());
    
  4. Customizing JSON dump options:

    Console.WriteLine(person.DumpAsJson(options => {
        options.Indented = false;
        options.MaxDepth = 5;
    }));
    

Object Dumping

The core feature of DotNetToolbox.ObjectDumper is to create a human-readable string representation of an object. It traverses the object graph and outputs a formatted string that shows the types, properties, and values.

JSON Object Dumping

In addition to the custom object dumping, the library also provides support for dumping objects as JSON strings using the System.Text.Json serializer, offering a familiar and standardized output.

Customization

DotNetToolbox.ObjectDumper allows extensive customization of the output format:

  • DumpBuilderOptions: Determines the behavior of the main object dumper. Users can configure indentation style, indent size, and whether to use full type names.
  • JsonDumpBuilderOptions: Configures the JSON object dumper, with options for indentation and maximum object graph traversal depth.

One of the powerful features of DumpBuilderOptions is the ability to define custom formatters for types. This allows you to control exactly how objects of certain types are represented in the output.

Custom Formatter Example:
  1. Defining a custom formatter for a type:
    string customDump = person.Dump(options => {
        options.CustomFormatters[typeof(DateTime)] = value => ((DateTime)value).ToString("yyyy-MM-dd");
    });
    Console.WriteLine(customDump);
    

In this example, all DateTime objects within the person object will be formatted using the "yyyy-MM-dd" format.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.1.1 134 8/24/2024
8.1.0 106 5/21/2024
8.0.4 140 2/5/2024
8.0.3 134 1/10/2024
8.0.2 136 1/8/2024

v8.0.3

     Stable release of DotNetToolbox.ObjectDumper, a versatile .NET 8 library that revolutionizes the way developers can view and log object states. Offering a rich set of features to transform any object into a readable and informative string format, this library is a must-have for debugging, logging, and understanding complex object hierarchies during application development.

     What's new:
     - Minor bug corrections.