Visual Studio 2015扩展以在类中生成ToString()方法 [英] Visual Studio 2015 extension to generate a ToString() method in a class

查看:79
本文介绍了Visual Studio 2015扩展以在类中生成ToString()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

扩展是指Visual Studio扩展.

With extension I meant a Visual Studio Extension.

我不知道是否有一种方法可以自动生成带有已创建扩展名的ToString方法.

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

我想要一个带有某些属性的类,并使用一种工具通过其属性生成ToString方法.

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.

这个问题 Visual中是否有ToString()生成器Studio 2010?没有回答我想要的,您不能使用代码段从类的属性中生成代码,只能添加代码或替换一些已创建的代码.

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.

推荐答案

在vs2015上,您可以构建一个CodeFix项目.请参见:构建CodeFix ex .在该项目中,您可以轻松添加将ToString添加为vs15新分析器的一部分的逻辑.

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.

选项2:我是OzCode团队的一员,我们创建了一个很棒的工具,它的功能之一就是在调试时动态创建自定义的"ToString"方法(在调试时),我在

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

这篇关于Visual Studio 2015扩展以在类中生成ToString()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆