如何在Visual Studio中自动生成多个getter / setter或访问器

时间:2022-09-24 21:37:19

Before I start, I know there is this post and it doesn't answer my question: How to generate getters and setters in Visual Studio?

在开始之前,我知道有这篇文章并且它没有回答我的问题:如何在Visual Studio中生成getter和setter?

In Visual Studio 2008 there is the ability to auto generate getters and setters (accessors) by right clicking on a private variable -> Refactor -> Encapsulate Field...

在Visual Studio 2008中,可以通过右键单击私有变量 - > Refactor - > Encapsulate Field来自动生成getter和setter(访问器)...

This is great for a class that has 2 or 3 methods, but come on MS! When have you ever worked with a class that has a few accessors?

这对于有2种或3种方法的课程来说非常棒,但是来自MS!你什么时候曾经和一个有几个访问者的班级一起工作过?

I am looking for a way to generate ALL with a few clicks (Eclipse folks out there will know what I am talking about - you can right click a class and select 'generate accessors'. DONE.). I really don't like spending 20 minutes a class clicking through wizards. I used to have some .NET 1.0 code that would generate classes, but it is long gone and this feature should really be standard for the IDE.

我正在寻找一种方法来点击几下生成ALL(那里的Eclipse人员会知道我在说什么 - 你可以右键单击一个类并选择'生成访问者'。完成。)。我真的不喜欢花20分钟一个班级点击向导。我曾经有一些.NET 1.0代码可以生成类,但它早已不复存在,这个功能应该是IDE的标准。

UPDATE: I might mention that I have found Linq to Entities and SQLMetal to be really cool ideas, and way beyond my simple request in the paragraph above.

更新:我可能会提到我发现Linq to Entities和SQLMetal是非常酷的想法,而且超出了我在上面段落中的简单请求。

4 个解决方案

#1


11  

Sorry, you really need to install Resharper to get approximately the same amount of refactoring support as you are used to in Eclipse.

抱歉,您确实需要安装Resharper才能获得与Eclipse中相同的重构支持。

However, Resharper gives you a dialog very similar to the one you are used to in Eclipse: Screenshot http://i35.tinypic.com/28a1004.png

但是,Resharper为您提供了一个非常类似于您在Eclipse中习惯的对话框:截图http://i35.tinypic.com/28a1004.png

#2


3  

I have an "info class generator" application that you can use an excel sheet and it will generate the private members and the public get/set methods.

我有一个“信息类生成器”应用程序,您可以使用Excel工作表,它将生成私有成员和公共get / set方法。

You can download it for free from my website.

您可以从我的网站免费下载。

#3


3  

In 2008 I don't bother with Encapsulate Field. I use the new syntax for properties:

在2008年,我不打扰Encapsulate Field。我使用属性的新语法:

public string SomeString { get; set; }

#4


0  

Possibly a macro. There are also addins (like ReSharper, which is great but commercial) capable of doing that quickly.

可能是一个宏。还有一些插件(比如ReSharper,它很棒,但很商业)能够快速完成。

#1


11  

Sorry, you really need to install Resharper to get approximately the same amount of refactoring support as you are used to in Eclipse.

抱歉,您确实需要安装Resharper才能获得与Eclipse中相同的重构支持。

However, Resharper gives you a dialog very similar to the one you are used to in Eclipse: Screenshot http://i35.tinypic.com/28a1004.png

但是,Resharper为您提供了一个非常类似于您在Eclipse中习惯的对话框:截图http://i35.tinypic.com/28a1004.png

#2


3  

I have an "info class generator" application that you can use an excel sheet and it will generate the private members and the public get/set methods.

我有一个“信息类生成器”应用程序,您可以使用Excel工作表,它将生成私有成员和公共get / set方法。

You can download it for free from my website.

您可以从我的网站免费下载。

#3


3  

In 2008 I don't bother with Encapsulate Field. I use the new syntax for properties:

在2008年,我不打扰Encapsulate Field。我使用属性的新语法:

public string SomeString { get; set; }

#4


0  

Possibly a macro. There are also addins (like ReSharper, which is great but commercial) capable of doing that quickly.

可能是一个宏。还有一些插件(比如ReSharper,它很棒,但很商业)能够快速完成。