csharp

Installation
SKILL.md

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, required members. Records for DTOs and value objects — value equality is what you want when comparing data, and hand-written Equals/GetHashCode pairs 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 if ladder 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 switch over the outcomes:

    public abstract record Result<T>
    {
        public sealed record Ok(T Value) : Result<T>;
        public sealed record Fail(string Error) : Result<T>;
    }
    
Installs
51
GitHub Stars
15
First Seen
May 4, 2026
csharp — alexander-danilenko/cortex-ai-skills