How can we generate getters and setters in Visual Studio?

后端 未结 16 2202
盖世英雄少女心
盖世英雄少女心 2020-12-07 07:46

By \"generate\", I mean auto-generation of the code necessary for a particular selected (set of) variable(s).

But any more explicit explication or comment on good pr

16条回答
  •  無奈伤痛
    2020-12-07 08:18

    In addition to the 'prop' snippet and auto-properties, there is a refactor option to let you select an existing field and expose it via a property (right click on the field → Refactor → Encapsulate Field...).

    Also, if you don't like the 'prop' implementation, you can create your own snippets. Additionally, a third-party refactoring tool like ReSharper will give you even more features and make it easier to create more advanced snippets. I'd recommend ReSharper if you can afford it.

    • http://msdn.microsoft.com/en-us/library/f7d3wz0k(VS.80).aspx

    • Video demonstrating the use of snippet 'prop' (among other things), at 3 min 23 secs.

提交回复
热议问题