简体   繁体   English

如何在VS类设计器中创建自动实现的属性

[英]How do I create auto-implemented properties in the VS class designer

I'm using the class designer in Visual Studio 2008 and when I add properties to my classes they are created with an empty setter and a getter that throws a NotImplementedException. 我在Visual Studio 2008中使用类设计器,当我向类中添加属性时,将使用空的setter和引发NotImplementedException的getter来创建属性。 In the properties window there's an option called "Auto-Implemented" which is always greye out. 在属性窗口中,有一个名为“自动实施”的选项,该选项始终不可用。 Is there a way to change the settings for this so by default new properties will be auto-implemented or some way to turn this option on so I don't have to keep editing the code each time I add in a new property? 有没有一种方法可以更改此设置,因此默认情况下将自动实现新属性,或以某种方式打开此选项,这样我每次添加新属性时都不必继续编辑代码?

AFAIK, you can't. AFAIK,您不能。 I asked this at Barcelona a year or so ago - I don't think anything has changed. 我大约一年前在巴塞罗那问过这个问题-我认为没有任何变化。 Basically, as I understand it, this is done directly (not via an editable snippet). 基本上,据我了解,这是直接完成的(而不是通过可编辑的代码段完成)。

For visual studio 2008 you could install this "power toys" that give you another option to class designer menu "create auto-implemented property" 对于Visual Studio 2008,您可以安装此“电动玩具”,该玩具为类设计器菜单“创建自动实现的属性”提供了另一个选项。

http://modeling.codeplex.com/ http://modeling.codeplex.com/

i'll waiting this for Visual Studio 2010 too... else it's so annoying 我也会等到Visual Studio 2010 ...否则太烦人了

您还可以使用snippet propfull ,然后使用Tab和Tab创建属性。

You can create field, and encapsulate it(Refactor->Encapsulate field). 您可以创建字段并将其封装(Refactor-> Encapsulate field)。
This can help for simple properties. 这可以帮助获得简单的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM