A collection of C# code snippets for the Zed editor.
- 100+ snippets covering various C# development scenarios
- Support for ASP.NET Core (MVC, Razor Pages, Minimal APIs)
- CQRS/MediatR patterns for clean architecture
- Testing frameworks (xUnit, NUnit, MSTest)
- Mocking with Moq
- Common boilerplates for classes, interfaces, controllers, and more
- Clone this repository
- Go to Extensions menu in Zed IDE
- Click "Install Dev Extension"
- Select the cloned folder e.g. (csharp-zed-snippets)
Type the snippet prefix and press Tab to expand the snippet. Use Tab to navigate between placeholders.
Basic C# constructs and common patterns:
| Prefix | Description |
|---|---|
class |
Create a new class |
record |
Creates a C# record declaration |
interface |
Create a new interface |
method |
Create a method |
Full file templates for common C# files:
| Prefix | Description |
|---|---|
bp_class |
Boilerplate for a new C# class |
bp_interface |
Boilerplate for a new C# interface |
bp_struct |
Boilerplate for a new C# struct |
Web development patterns for ASP.NET Core:
| Prefix | Description |
|---|---|
httpget |
Creates an HTTP GET action method |
httppost |
Creates an HTTP POST action method |
httpput |
Creates an HTTP PUT action method |
httpdelete |
Creates an HTTP DELETE action method |
Patterns for Command Query Responsibility Segregation with MediatR:
| Prefix | Description |
|---|---|
cqrs_command |
Creates a CQRS command with MediatR IRequest |
cqrs_handler |
Creates a CQRS command handler with MediatR |
cqrs_query |
Creates a CQRS query with MediatR IRequest |
cqrs_query_handler |
Creates a CQRS query handler with MediatR |
cqrs_command_validator |
Creates a FluentValidation validator for command |
Unit testing patterns for popular frameworks:
| Prefix | Description |
|---|---|
xclass |
Basic xUnit test class with constructor setup |
fact |
xUnit [Fact] test method with AAA pattern |
facta |
xUnit async [Fact] test method |
theory |
xUnit [Theory] with InlineData |
Type bp_apicontroller and press Tab:
using Microsoft.AspNetCore.Mvc;
namespace MyNamespace
{
[ApiController]
[Route("api/[controller]")]
public class NewApiController : ControllerBase
{
}
}Type cqrs_command and press Tab:
public class CreateEntityCommand : IRequest<int>
{
public string Name { get; set; }
}Type fact and press Tab:
[Fact]
public void MethodName_ShouldExpectedBehavior_WhenState()
{
// Arrange
// Act
// Assert
}Contributions are welcome! Please feel free to submit a Pull Request.
The snippets are organized in the src/ directory by category for easier maintenance:
src/boilerplate.json- Full file templatessrc/cqrs.json- CQRS/MediatR patternssrc/general.json- Basic C# constructssrc/tests.json- Testing framework snippetssrc/web.json- ASP.NET Core snippets
To combine all snippet files into the final snippets/csharp.json file used by Zed, run:
node src/combine.js
The src/combine.js script is used by these shell scripts to merge all category files into a single snippet file. Always run the combine script after making changes to any files in the src/ directory.
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Kenneth Joshua Becaro (joshuabecaro@gmail.com)
https://github.com/kenBinary/csharp-zed-snippets
If you have suggestions for new snippets or improvements, please open an issue on GitHub!