Skip to content

gayaK/ToString

 
 

Repository files navigation

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.

Usage

See also Fody usage.

NuGet installation

Install the ToString.Fody NuGet package and update the Fody NuGet package:

PM> Install-Package ToString.Fody
PM> Update-Package Fody

The Update-Package Fody is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.

Add to FodyWeavers.xml

Add <ToString/> to FodyWeavers.xml

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <ToString/>
</Weavers>

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

About

Generate ToString method from public properties.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%