AgentStack
SKILL verified MIT Self-run

C# Best Practices

skill-ngxtm-devkit-best-practices · by ngxtm

Idiomatic C# patterns for clean, maintainable code.

No reviews yet
0 installs
14 views
0.0% view→install

Install

$ agentstack add skill-ngxtm-devkit-best-practices

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of C# Best Practices? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

C# Best Practices

Priority: P1 (OPERATIONAL)

Idiomatic patterns for clean, maintainable C# code.

Implementation Guidelines

  • Naming Conventions:
  • PascalCase: Types, methods, properties, events, namespaces
  • camelCase: Parameters, local variables
  • _camelCase: Private fields
  • IPascalCase: Interfaces (prefix with I)
  • TPascalCase: Type parameters (prefix with T)
  • Project Structure: Clean/Onion architecture. Feature folders over layer folders.
  • Dependency Injection: Constructor injection only. Register in IServiceCollection.
  • Logging: ILogger with structured logging. Use appropriate log levels.
  • Configuration: IOptions pattern with validation. Never hardcode settings.
  • File Organization: One type per file. Use global using for common namespaces.
  • Immutability: Prefer readonly, init, record for data integrity.
  • Expression-bodied Members: Use for simple single-line methods/properties.

Anti-Patterns

  • No static services: Use DI instead of static class ServiceHelper.
  • No service locator: Avoid IServiceProvider.GetService() in business logic.
  • No new() for dependencies: Inject via constructor.
  • No magic strings: Use nameof(), constants, or configuration.
  • No God classes: Split large classes by responsibility.
  • No regions: Use partial classes or extract types instead.

Code

// Proper DI registration
public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddApplicationServices(this IServiceCollection services)
    {
        services.AddScoped();
        services.AddScoped();

        services.AddOptions()
            .BindConfiguration("Email")
            .ValidateDataAnnotations()
            .ValidateOnStart();

        return services;
    }
}

// Structured logging with semantic names
public class OrderService(IOrderRepository repo, ILogger logger)
{
    public async Task GetOrderAsync(int orderId, CancellationToken ct)
    {
        logger.LogDebug("Fetching order {OrderId}", orderId);

        var order = await repo.GetByIdAsync(orderId, ct);

        if (order is null)
            logger.LogWarning("Order {OrderId} not found", orderId);

        return order;
    }
}

// Options pattern with validation
public class EmailSettings
{
    public const string SectionName = "Email";

    [Required]
    public string SmtpHost { get; init; } = string.Empty;

    [Range(1, 65535)]
    public int SmtpPort { get; init; } = 587;

    [Required, EmailAddress]
    public string FromAddress { get; init; } = string.Empty;
}

Reference & Examples

For project structure templates and DI patterns: See [references/REFERENCE.md](references/REFERENCE.md).

Related Topics

language | security | tooling

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.