问题
With extension I meant a Visual Studio Extension.
I wan't 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 wan't 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. Specially the project type I need to create. I thought in a Code Refactor project but I'm not sure If it's what I need.
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.
回答1:
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
来源:https://stackoverflow.com/questions/40506922/visual-studio-2015-extension-to-generate-a-tostring-method-in-a-class