⚡ Type 3 Letters, Get 20 Lines
Writing same boilerplate over and over? Custom snippets let you type ‘prop’ and get full property with backing field.
Built-in Snippets You Should Know
| Shortcut | Expands To |
|---|---|
| prop | Auto-property |
| ctor | Constructor |
| for | For loop |
| foreach | Foreach loop |
| try | Try-catch block |
| cw | Console.WriteLine() |
Usage: Type shortcut → Press Tab twice
Create Your Own Snippet
Step 1: Tools → Code Snippets Manager → New Snippet
API Controller apicontroller Creates REST API controller Get() { var result = await _service.GetAllAsync(); return Ok(result); } [HttpGet("{id}")] public async TaskGet(int id) { var result = await _service.GetByIdAsync(id); return result != null ? Ok(result) : NotFound(); } [HttpPost] public async Task Post($EntityName$ entity) { var result = await _service.CreateAsync(entity); return CreatedAtAction(nameof(Get), new { id = result.Id }, result); } }$end$]]> ControllerName User ServiceName IUserService EntityName User
Step 2: Save as MySnippet.snippet → Import in Snippets Manager
Step 3: Type ‘apicontroller’ + Tab → Full REST controller ready!
🎯 My Favorite Custom Snippets
- testmethod: Complete xUnit test method with Arrange/Act/Assert comments
- repo: Full repository pattern class with CRUD
- dto: DTO class with common properties
- efconfig: Entity Framework configuration class
- apiget: HttpGet endpoint with error handling
💡 Pro Tips
- Use $end$: Cursor jumps here when done filling placeholders
- Default values: Pre-fill common values to save time
- Share snippets: Export and share .snippet files with team
- GitHub has templates: Search ‘Visual Studio snippets’ for ready-made collections
“Created 15 custom snippets for our architecture patterns. New team members productive in 1 day. No more copy-pasting from old files. Type 3 letters, get perfect boilerplate.”
⚡ Time Saved
90%
Less typing
0
Syntax errors
5x
Faster dev
