Visual Studio 2015 extension to generate a ToString() method in a class
Asked Answered
T

1

2

With extension I meant a Visual Studio Extension.

I want to know if there's a way to autogenerate a ToString method with an already created extension.

I want to have a class with some properties and use a tool to generate the ToString method using its properties.

class A {
    String propA { get; set; }
    String propB { get; set; }

    // Autogenerated
    override ToString() 
    {
        return "propA = " + propA + ", propB" + propB;
    }
}

If not, I want to know how can I make one. I searched the web but I can't find the correct way to add custom code to a already created class with a extension. Especially the project type I need to create.

Edit: This question Is there a ToString() generator available in Visual Studio 2010? didn't answer what I want; you can't use a snippet to generate code from the properties of the class. You can only add code or replace some created code.

Taxidermy answered 9/11, 2016 at 12:20 Comment(9)
can you elaborate a little more?Oryx
you can always override the ToString method in your class.Oryx
Maybe you could post some code that you have tried or just add more detail.Malina
class can have more than one extension ... I dont undestand what is a problem....Xenophon
Possible duplicate of Is there a ToString() generator available in Visual Studio 2010?Remount
That question didn't answer mine. Also, snippets can't generate the code I wantTaxidermy
You need to create a vsix project and create your own extension. How to set up this you can search msdn. There you can implement all logic you would like.Mash
But I don't know what I need to create in the vsix, I couldn't find the information to do what I want (modify an existing class with custom code)Taxidermy
Sounds like a Code Refactor project to me, which means you're going to need to get into Roslyn. There's samples here that might help: github.com/dotnet/roslyn/wiki/Samples-and-WalkthroughsGlassworks
P
0

On vs2015 you can build a CodeFix project. see: Build CodeFix ex. On that project you can easely add your logic for adding ToString as part of vs15 new Analyzers.

Option 2: I'm part of OzCode team and we create a great tool that one of it's features is to create a custom "ToString" method, on the fly (while debugging) I'm adding a linq the the Reveal feature

Pulsar answered 9/11, 2016 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.