csharp
Skill16 starsChanged 4 months agoMITView on GitHub
Apply these opinionated C# conventions whenever writing or reviewing C# 12 / .NET 8+ code: nullable enabled with warnings as errors, records and primary constructors, pattern matching over cast chains, the Result pattern for expected failures, async all the way with CancellationToken, IOptions config, IHttpClientFactory, and never returning EF entities from an API.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- jnotsknab/mux-swarmtheir own version, first seen Jun 29, 2026
- ffsshhttiikk/opencode-agents-skillstheir own version, first seen Feb 28, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- jnotsknab/mux-swarm★ 9same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- documentationSkill
- dotnet-coreSkill
- humanize-textSkill
- javascriptSkill
- jira-report-commentSkill
- legacy-modernizationSkill
- nestjsSkill
- nextjsSkill
- pythonSkill
- reactSkill
- simple-englishSkill
- spec-miningSkill
- testingSkill
- typescriptSkill
The file
Files
C# Conventions
House conventions for C# 12 / .NET 8+. Apply them to code you are writing or changing — don't rewrite untouched files to match unless asked.
Conventions
<Nullable>enable</Nullable>and warnings as errors. The nullable annotations only pay off if the warnings block the build; ignored, they become decoration that lies about which references can be null.- C# 12 defaults: file-scoped namespaces, primary constructors, collection expressions,
requiredmembers. Records for DTOs and value objects — value equality is what you want when comparing data, and hand-writtenEquals/GetHashCodepairs drift apart. - Pattern matching over type-test-and-cast chains. Switch expressions on a closed hierarchy let the compiler warn about unhandled cases; an
if/else ifladder just falls through silently when a new type appears. Result pattern for expected failures, exceptions for genuinely exceptional ones. "Not found" and "invalid input" are ordinary outcomes and belong in the return type where the caller must deal with them; using exceptions for control flow hides them from the signature and costs a stack unwind per occurrence. A closed record hierarchy gives you exhaustive
switchover the outcomes:public abstract record Result<T> { public sealed record Ok(T Value) : Result<T>; public sealed record Fail(string Error) : Result<T>; } var message = GetUser(id) switch { Result<User>.Ok(var user) => $"Found {user.Name}", Result<User>.Fail(var error) => error, };- Async all the way down.
.Resultand.Wait()deadlock under a synchronisation context and burn a thread pool thread everywhere else. If a call chain has to be async at the bottom, it is async at the top. - Accept and pass a
CancellationTokenon every async public method. Without it a cancelled request keeps its database query and HTTP call running to completion, and the work is charged to a caller who has already gone. - Never expose EF entities from an API. Project to a DTO with
Select— otherwise you ship whatever the schema grows next, and lazy loading turns serialisation into an N+1 query storm. - EF specifics that show up as production incidents rather than test failures:
AsNoTracking()on every read-only query, since change tracking on a large result set is pure overhead;AsSplitQuery()whenInclude-ing more than one collection, because a single join multiplies rows cartesian-style;ExecuteUpdateAsync/ExecuteDeleteAsync(.NET 7+) for bulk changes rather than loading entities to modify them; a globalHasQueryFilterfor soft deletes so no query can forget the flag. - Keyed services when one interface has several implementations (.NET 8): register with
AddKeyedScoped<INotifier, EmailNotifier>("email")and resolve with[FromKeyedServices("email")]. It beats an enum-switching factory because the container still owns the lifetimes. IOptions<T>with validated, strongly-typed config.configuration["Some:Key"]fails at the call site, at runtime, on a typo. A bound options class withValidateOnStartfails at boot with the field named.IHttpClientFactory, nevernew HttpClient()per call — socket exhaustion from lingering TIME_WAIT connections is the classic failure, and it only appears under load.Span<T>/Memory<T>and pooling where a profiler says allocations matter. They complicate the code, so spend that complexity where there is a measurement, not on principle.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

