/ToString

Generate ToString method from public properties.

Primary LanguageC#MIT LicenseMIT

Chat on Gitter NuGet Status

This is an add-in for Fody

Icon

Generates ToString method from public properties for class decorated with a [ToString] Attribute.

Introduction to Fody.

The nuget package

https://nuget.org/packages/ToString.Fody/

PM> Install-Package ToString.Fody

Your Code

[ToString]
class TestClass
{
    public int Foo { get; set; }

    public double Bar { get; set; }
    
    [IgnoreDuringToString]
    public string Baz { get; set; }
}

What gets compiled

class TestClass
{
    public int Foo { get; set; }

    public double Bar { get; set; }
    
    public string Baz { get; set; }
    
    public override string ToString()
    {
        return string.Format(
            CultureInfo.InvariantCulture, 
            "{{T: TestClass, Foo: {0}, Bar: {1}}}",
            this.Foo,
            this.Bar);
    }
}

Icon

Icon courtesy of The Noun Project