Skip to content

Meaningful ToString() is an extremely lightweight .NET class library that helps describe your instances in a more meaningful way.

License

Notifications You must be signed in to change notification settings

meridian-tcs/meaningful-tostring

Repository files navigation

Meaningful ToString()

Build Status Badge Downloads Badge Version Badge

Meaningful ToString() is an extremely lightweight .NET class library that helps describe your instances in a more meaningful way.

The default object.ToString() isn't very useful when debugging or logging. Meaningful ToString() creates a string that looks something like:

"Employee (Id = 13298279, Title = Head of Sales, FirstName = Fred, LastName = Smith, Emails = System.String[], Manager = Employee (Id = 13298278, Title = Managing Director, FirstName = Joe, LastName = Bloggs, Emails = System.String[], Manager = null))"

And this is all that Meaningful ToString() does!

Requirements

Meaningful ToString() is a .NET Standard 1.0 library, and can be used in the following .NET environments:

  • dotnet Core (CoreCLR) projects (versions 1 and up);
  • full-fat .NET framework, v4.5 and beyond

Quick Start Guide

  1. Include the NuGet package:

    Install-Package Meridian.MeaningfulToString

  2. Alter your class to inherit from Meridian.MeaningfulToString.MeaningfulBase

    For example:

    public class Employee : Meridian.MeaningfulToString.MeaningfulBase
    {
      public int Id
      {
        get;
        set;
      }
      
      // TODO: ... the rest of your class implementation here ...
    }
    
    • Note 1: You can have multiple base classes - just as long as ultimately, the class you want meaningful values for ToString() inherits from MeaningfulBase.
    • Note 2: This is actually not 100% required; this is just the quick start. If you'd rather not inherit all your classes from this base class, see below section "Without Inheriting from MeaningfulBase".
  3. That's it! Start debugging/logging!

Without Inheriting from MeaningfulBase

You don't have to inherit from MeaningfulBase if you don't want to. Simply override your class' implementation of ToString(), and call the object extension method MeaningfulToString():

public override string ToString()
{
    return this.MeaningfulToString();
}

As with all extension methods, just remember to make sure to include the Meridian.MeaningfulToString namespace in your usings:

using Meridian.MeaningfulToString;

About

Meaningful ToString() is an extremely lightweight .NET class library that helps describe your instances in a more meaningful way.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages