DotNetToolbox.ObjectDumper 8.1.1

dotnet add package DotNetToolbox.ObjectDumper --version 8.1.1                
NuGet\Install-Package DotNetToolbox.ObjectDumper -Version 8.1.1                
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.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetToolbox.ObjectDumper --version 8.1.1                
#r "nuget: DotNetToolbox.ObjectDumper, 8.1.1"                
#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.1.1

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

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. Extension Methods
  4. Object Dumping
  5. JSON Object Dumping
  6. 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

Dump and DumpAsJson 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

DotNetToolbox.ObjectDumper Version 8.1.1

     Stable release of DotNetToolbox.ObjectDumper, a .NET 8 library with a powerful extension for converting objects into a human-readable string representations.