跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
其他技能

csharp-house-style

The house C# style enforced by .editorconfig and the build - this. qualification, usings inside file-scoped namespaces, discards, regions, primary constructors, nullable and naming. Use whenever writing or reviewing C# in this solution.

LeanMeanCleanApps · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add LeanMeanCleanApps/CleanMinimalApi --skill csharp-house-style

技能说明


name: csharp-house-style description: The house C# style enforced by .editorconfig and the build - this. qualification, usings inside file-scoped namespaces, discards, regions, primary constructors, nullable and naming. Use whenever writing or reviewing C# in this solution. metadata: scope: shared

C# house style

The rule

.editorconfig holds the style and the build enforces it (EnforceCodeStyleInBuild, AnalysisLevel latest-recommended, TreatWarningsAsErrors, all in Directory.Build.props). If the build is clean and dotnet format --verify-no-changes passes, the style is right. These are the parts that differ from most .NET code, so they're the ones people trip on.

RuleLooks like
File-scoped namespace first, then using directives inside itnamespace X.Y; then using Mediator;
Qualify members with this.this.context.Reviews, this.RuleFor(...)
Discard unused results with _ =_ = services.AddScoped<...>();
var everywherevar result = ...
Braces on every if, Allman styleopening brace on its own line
Block bodies for methods and constructorsno => expression methods
Primary constructors for injected servicespublic class XHandler(IRepo repository)
#region to group long classes#region Authors ... #endregion Authors
Nullable reference types onstring? when null is a real value
Collection expressions[.. result.Select(...)], List<T> x = [];
Async methods return ValueTask in handlers, Task in repositoriesas the interfaces declare

Naming: PascalCase types and members, camelCase locals and parameters, no underscores on fields (this. tells you it's a field). Interfaces start with I.

Steps

  1. Write the code to match a neighbouring file.
  2. Run dotnet format to fix whitespace and using order.
  3. Run dotnet build and fix every warning. Nullable warnings are fixed with real null handling, not !, except for EF navigation properties (= null!).

Don't

  • Move usings above the namespace or drop this. to match another codebase.
  • Add #pragma warning disable or <NoWarn> to quiet an analyser.
  • Use _camelCase fields.
  • Leave unused usings; IDE0005 fails the build.

Check

dotnet format --verify-no-changes
dotnet build