Csharp

Write idiomatic C# code using .NET features, async/await, LINQ, SOLID principles, dependency injection, and unit tests.

NeuralBlitz Updated 1 repo stars

File contents

What I do

  • Write idiomatic C# code
  • Use .NET features effectively
  • Implement async/await patterns
  • Use LINQ for queries
  • Apply SOLID principles
  • Handle exceptions properly
  • Use dependency injection
  • Write unit tests

When to use me

When writing C# or .NET code.

C# Best Practices

// Async/await patterns
public async Task<UserDto> GetUserAsync(int id)
{
    return await _repository.GetByIdAsync(id)
        .ConfigureAwait(false);
}

// LINQ queries
var activeUsers = await _context.Users
    .Where(u => u.IsActive)
    .OrderBy(u => u.CreatedAt)
    .Skip(page * pageSize)
    .Take(pageSize)
    .ToListAsync();

// Dependency injection
services.AddScoped<IUserService, UserService>();
services.AddSingleton<IConfiguration>(Configuration);

// Records for DTOs
public record UserDto(
    int Id,
    string Email,
    string Name,
    DateTime CreatedAt);

// Pattern matching
public decimal CalculateDiscount(Order order) => order switch
{
    { IsPremium: true } => 0.2m,
    { Items.Count: > 10 } => 0.1m,
    { Total: > 100 } => 0.05m,
    _ => 0m
};

NeuralBlitz/Agent-Gateway/tree/main/agent-gateway/skills/user/csharp commit 467ada4a48

Frequently asked questions

npx skillmds@latest add neuralblitz/csharp