dotnet-guidelines

Enforces C# coding guidelines and dotnet best practices for code review.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/roeibajayo/claude-tools --skill dotnet-guidelines
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-guidelines
Source: https://github.com/roeibajayo/claude-tools/tree/main/.claude/skills/dotnet-guidelines
Command: npx skills add https://github.com/roeibajayo/claude-tools --skill dotnet-guidelines

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill codifies C# coding guidelines and best practices to reduce bugs and improve maintainability across .NET projects.

Core Features & Use Cases

  • Always use Primary Constructors for classes.
  • Always prefer record types for immutable data structures.
  • Never mix multiple classes or DTOs in a single file; filename MUST match the class/DTO name (e.g., UserDto.cs).
  • Avoid private fields prefixed with _.
  • Add a trailing period to all server-side log messages.
  • Use string? for nullable strings.
  • Use var for local variables when the type is obvious.
  • Avoid Regions in code files.
  • Use collection initializers and static lambdas when applicable.
  • Always seal accessors for classes or records if not intended for inheritance.
  • Always use internal for internal classes or records.
  • Never inject HttpClient/IHttpClientFactory; use IRestClient.
  • Never register services directly in IServiceCollection; use ITransientService, IScopedService, or ISingletonService.
  • Always use ILogger with structured logging.
  • Always use cancellation tokens for asynchronous methods.
  • Always use IMemoryCore for time-based in-memory caching.
  • Always use DTOs for API communication, validated with attributes.
  • Always name lambda parameters with x.
  • Never use try-catch blocks solely to log and rethrow exceptions.
  • If backend changes are made, run dotnet build to ensure no errors.

Quick Start

Review a .cs file (e.g., UserService.cs) to verify primary constructors, immutable DTO usage, and absence of Regions; propose concrete fixes.

Frequently Asked Questions about dotnet-guidelines

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce C# coding guidelines across my .NET project?

Enforce C# coding guidelines by applying standards for primary constructors, record types, file naming, nullable references, and access modifiers during code review. This Skill validates these practices against your codebase and proposes concrete fixes to improve consistency and maintainability.

What are C# best practices for class design and naming conventions?

C# best practices include using primary constructors for all classes, sealing accessors unless inheritance is intended, matching filenames to class names, avoiding private field prefixes, and using `internal` for internal classes. These conventions reduce bugs and improve code clarity.

How should I structure DTOs and API communication in C#?

Always use DTOs for API communication, validated with attributes, and place each DTO in its own file matching the class name. Prefer `record` types for immutable data structures and use `string?` for nullable strings to enforce type safety.

What dependency injection patterns should I use in .NET services?

Never inject `HttpClient` or `IHttpClientFactory` directly; use `IRestClient`. Register services through `ITransientService`, `IScopedService`, or `ISingletonService` instead of directly in `IServiceCollection` to maintain consistency and testability.

What logging and asynchronous method patterns does C# best practice recommend?

Use `ILogger` with structured logging and add trailing periods to all server-side log messages. Always include cancellation tokens in asynchronous methods and use `IMemoryCore` for time-based in-memory caching to follow .NET conventions.

When should I avoid try-catch blocks and use regions in C# code?

Never use try-catch blocks solely to log and rethrow exceptions, and avoid regions in code files entirely. These anti-patterns reduce readability; use proper logging practices and structured exception handling instead.