clean-code-dotnet

Enforce clean-code standards for C#/.NET projects during code reviews.

24|5|Updated Nov 28, 2025
One-click install
npx skills add https://github.com/thapaliyabikendra/ai-artifacts --skill clean-code-dotnet
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clean-code-dotnet
Source: https://github.com/thapaliyabikendra/ai-artifacts/tree/main/.claude/skills/clean-code-dotnet
Command: npx skills add https://github.com/thapaliyabikendra/ai-artifacts --skill clean-code-dotnet

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill guides you in writing clean, elegant, and maintainable .NET code, solving the challenge of complex, hard-to-understand, and difficult-to-test codebases. It promotes best practices, design principles, and coding standards that lead to higher quality software and improved team productivity.

Core Features & Use Cases

  • SOLID Principles: Explains and demonstrates the Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles.
  • Naming Conventions & Formatting: Provides guidelines for consistent and descriptive naming, along with .editorconfig templates for automated code style enforcement.
  • Refactoring Techniques: Covers common refactoring patterns to improve code structure, reduce complexity, and enhance readability without changing external behavior.
  • Testability & Modularity: Emphasizes writing code that is easy to unit test and designing modules with clear responsibilities and minimal coupling.
  • Use Case: A development team is struggling with a legacy .NET application that is difficult to extend and test. Using this skill, they apply SOLID principles and refactoring techniques to gradually improve the codebase's quality and maintainability.

Quick Start

Refactor a C# class that handles both data storage and business logic to adhere to the Single Responsibility Principle (SRP).

Frequently Asked Questions about clean-code-dotnet

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

FAQPage Schema
How do I apply SOLID principles to improve my C# codebase?

SOLID principles—Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion—guide .NET code design by separating concerns, reducing coupling, and improving testability. Each principle addresses a specific structural problem: SRP ensures classes do one thing, OCP allows extension without modification, LSP guarantees safe inheritance, ISP prevents fat interfaces, and DI decouples dependencies. Apply them incrementally during refactoring to make code easier to test, extend, and maintain.

What's the best way to refactor a .NET class with multiple responsibilities?

Identify distinct responsibilities within the class and extract each into a separate class, applying Single Responsibility Principle. Use dependency injection to wire the new classes together, reducing coupling. This refactoring improves testability by allowing each responsibility to be tested in isolation, reduces side effects, and makes the code clearer. Start with the largest or most frequently changing responsibility.

How do I write C# code that's easier to unit test?

Testable C# code relies on loose coupling, clear module boundaries, and minimal external dependencies. Use dependency injection to inject dependencies rather than hardcoding them, apply SOLID principles to separate concerns, avoid magic strings and static calls, and ensure error handling is explicit. These practices enable isolated unit tests that verify behavior without external systems.

Can I enforce consistent code style across a .NET team automatically?

Yes, use `.editorconfig` files to define and enforce consistent naming, formatting, and style conventions automatically across your .NET projects. This removes manual code review friction, ensures adherence to naming standards and clean-code practices, and lets the team focus on logic and design rather than style disputes. Configure rules once and apply team-wide.

Why does my .NET code have guard clauses and how do they improve readability?

Guard clauses are early returns that check preconditions and exit if invalid, flattening nested conditionals and improving readability. Instead of deep `if-else` trees, guard clauses handle error cases upfront, making the happy path obvious and reducing cognitive load. They also enforce fail-fast error handling and reduce complexity.

What async patterns should I follow in C# to avoid common pitfalls?

Async C# code should use `async/await` consistently, avoid blocking calls like `.Result`, use `ConfigureAwait(false)` in libraries, and ensure proper cancellation token propagation. Follow naming conventions that include `Async` suffix, handle exceptions correctly in async methods, and prefer `Task` over `void` except for event handlers. These practices prevent deadlocks, improve responsiveness, and aid debugging.