摘自:《pro C#2010 and the .NET 4 Platform》
One way to activate a code snippet is to right-click the mouse and activate the Insert Snippet (or Surround With) menu option. Here, you will find a list of all code snippets of this category (press the Esc key to dismiss the pop-up menu). As a shortcut, however, you can simply type in the name of the code snippet, foreach in this case.
Once you find the snippet you want to activate, press the Tab key twice. This will autocomplete the entire snippet and leave a set of placeholders that you can fill in to complete the snippet. If you press the Tab key, you can cycle between each placeholder and fill in the gaps (press the Esc key to exit the code snippet edit mode.
If you were to right-click and select the Surround With menu, you would likewise be presented with a list of options. Recall that when using Surround With snippets, typically you first select a block of code statements to represent what should be used to wrap them (e.g., try/catch block). Be sure to take time to explore these predefined code expansion templates, as they can radically speed up the development process.
All code expansion templates are XML-based descriptions of the code to generate within the IDE. Using Visual Studio 2010 (as well as Visual C# 2010 Express), you can create your own custom code templates. Details of how to do so can be found in my article “Investigating Code Snippet Technology” at http://msdn.microsoft.com.
本文介绍了在Visual Studio 2010中如何利用代码片段提高开发效率,包括激活、填充占位符及自定义模板的方法。
209

被折叠的 条评论
为什么被折叠?



