Coder Social home page Coder Social logo

camilohe / objectdumper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thomasgalliker/objectdumper

0.0 1.0 0.0 8.91 MB

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

C# 99.28% Batchfile 0.72%

objectdumper's Introduction

ObjectDumper.NET

Version Downloads

ObjectDumper

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 listPerson = new List<Person>
{
  new Person
  {
    Name = "John",
    Age = 20
  },
  new Person
  {
    Name = "Thomas",
    Age = 30
  }
};

License

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

objectdumper's People

Contributors

ericnewton76 avatar thomasgalliker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.