• Stars
    star
    395
  • Rank 109,040 (Top 3 %)
  • Language
    C#
  • Created over 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ObjectDumper is a utility which aims to serialize C# objects to string for debugging and logging purposes.

ObjectDumper.NET

Version Downloads

ObjectDumper is a utility which aims to serialize C# objects to string for debugging and logging purposes.

Download and Install ObjectDumper.NET

This library is available on NuGet: https://www.nuget.org/packages/ObjectDumper.NET/ Use the following command to install ObjectDumper using NuGet package manager console:

PM> Install-Package ObjectDumper.NET

You can use this library in any .NET project which is compatible to PCL (e.g. Xamarin Android, iOS, Windows Phone, Windows Store, Universal Apps, etc.)

The Purpose of ObjectDumper

Serialization, the process of converting a complex object to a machine-readable or over-the-wire transmittable string, is a technique often used in software engineering. A well-known serializer is Newtonsoft.JSON which serializes .NET objects to the data representation format JSON.

ObjectDumper.NET provides two excellent ways to visualize in-memory .NET objects:

  • DumpStyle.Console: serialize objects to human-readable strings, often used to write complex C# objects to log files.
  • DumpStyle.CSharp: serialize objects to C# initializer code, which can be used to compile a C# object again.

API Usage

Dumping C# Objects to Console.WriteLine

The following sample program uses DumpStyle.Console to write C# objects to the console output:

static void Main(string[] args)
{
    var persons = new List<Person>
    {
        new Person { Name = "John", Age = 20, },
        new Person { Name = "Thomas", Age = 30, },
    };

    var personsDump = ObjectDumper.Dump(persons);

    Console.WriteLine(personsDump);
    Console.ReadLine();
}

//CONSOLE OUTPUT:
{ObjectDumperSample.Netfx.Person}
  Name: "John"
  Age: 20
{ObjectDumperSample.Netfx.Person}
  Name: "Thomas"
  Age: 30

Dumping C# initializer code from in-memory objects to Console.WriteLine

The following sample program uses DumpStyle.CSharp to write C# initializer code from in-memory to the console output:

static void Main(string[] args)
{
    var persons = new List<Person>
    {
        new Person { Name = "John", Age = 20, },
        new Person { Name = "Thomas", Age = 30, },
    };

    var personsDump = ObjectDumper.Dump(persons, DumpStyle.CSharp);

    Console.WriteLine(personsDump);
    Console.ReadLine();
}

//CONSOLE OUTPUT:
var listOfPersons = new List<Person>
{
  new Person
  {
    Name = "John",
    Age = 20
  },
  new Person
  {
    Name = "Thomas",
    Age = 30
  }
};

Strong-named assembly

This assembly is signed with the key ObjectDumper.snk in this repository.

Public key (hash algorithm: sha1):

00240000048000009400000006020000002400005253413100040000010001008da06ec8c6bd242c52102a9fc293b7af32f183da0d069f7c9522f063cacc3cc584668dfd6cf0560577380822b0c46fdb19e44fc78fad5e8d15b2c24a8766e2769c942705442926b3dcce385eac263893a4b6916976324544792ba1fb4697ab0d1bf28f3c8f0512234fa0a7b732141f7dc4b4a340bdaa95a6c1460c6a699e65c3

Public key token is fcc359471136d8b8.

In order to get these values, run following commands:

  • Extract public key of snk: sn -p ObjectDumper.snk public.key
  • Display public key: sn -tp public.key

Links

License

This project is Copyright © 2023 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.

More Repositories

1

ValueConverters.NET

A collection of commonly used IValueConverters for .NET applications
C#
147
star
2

Diacritics.NET

Finds and replaces diacritics in strings
C#
72
star
3

EntityFramework.Toolkit

EntityFramework best practices, patterns, utilities and extensions
C#
67
star
4

Plugin.FirebasePushNotifications

Receive and handle firebase push notifications in .NET MAUI apps
C#
60
star
5

CameraScanner.Maui

Camera preview and barcode scanner for .NET MAUI apps
C#
24
star
6

HttpClient.Caching

Caching Extension for .NET HttpClient
C#
21
star
7

PushNotifications.Server

Server-side .NET SDK for Apple APNS and and Google FCM
C#
20
star
8

EmployeeManagement

Multi-layer demo application
C#
18
star
9

EnumUtils

Commonly used .NET Enum utilities
C#
16
star
10

NCrontab.Scheduler

NCrontab.Scheduler is a simple, open source task scheduling system that can be used in any .NET application
C#
14
star
11

TypeConverter

TypeConverter is a lightweight, portable class library which allows to convert between objects of different types.
C#
12
star
12

ObservableView

Collections overlay for searching, filtering, sorting and grouping
C#
12
star
13

HighlightMarker

A simple-to-use highlight marker for search text highlighting
C#
11
star
14

XmlSerializerHelper

Serializes and deserializes any .Net object from/to XML
C#
11
star
15

Plugin.SegmentedControl.Maui

Segmented control for .NET MAUI apps
C#
10
star
16

EFCore.Toolkit

EntityFrameworkCore best practices, patterns, utilities and extensions
C#
9
star
17

Guards

Protects your public APIs
C#
9
star
18

CrossPlatformLibrary

An extensible cross-platform toolkit which provides a basic set of functionality used in most mobile apps.
C#
9
star
19

CrossPlatformLibrary.WebBrowser

CrossPlatformLibrary.WebBrowser is a cross-platform abstraction which allows to open browser requests
C#
5
star
20

ResourceLoader

A utility for reading embedded resources from assemblies
C#
5
star
21

CrossPlatformLibrary.Geolocation

C#
5
star
22

Paging.NET

Paging.NET is a basic toolkit which provides incremential server-side data loads.
C#
4
star
23

Tracing.NET

An extensible logging/tracing framework for all major .Net platforms.
C#
4
star
24

NuGetUtils

A command-line utility to delete/unlist NuGet packages
C#
4
star
25

PiWeatherStation

Weather Station for RasperryPi and Waveshare ePaper Displays
C#
3
star
26

MauiPopups

C#
3
star
27

CrossPlatformLibrary.Settings

C#
2
star
28

NLog.Targets.AppCenter

NLog targets for Microsoft.AppCenter
C#
1
star
29

RaspberryPi.NET

C#
1
star
30

OpenWeatherMap.API

OpenWeatherMap API client for .NET
C#
1
star
31

MeteoSwissApi

.NET API for Swiss national weather provider MeteoSwiss
C#
1
star
32

MauiMocks

Library for running Microsoft.Maui inside of unit tests
C#
1
star