From 097cec41c28fb1bc3911dfa8f370926461a777e6 Mon Sep 17 00:00:00 2001 From: Julian lechner Date: Wed, 30 Sep 2026 08:39:23 +0200 Subject: [PATCH] docs(csharp): require null-safe code --- shared/rules/csharp/references/types-and-collections.md | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/rules/csharp/references/types-and-collections.md b/shared/rules/csharp/references/types-and-collections.md index 8fbc15d..f9e49c7 100644 --- a/shared/rules/csharp/references/types-and-collections.md +++ b/shared/rules/csharp/references/types-and-collections.md @@ -3,6 +3,7 @@ Apply these rules when designing type contracts, choosing collection shapes, or exposing data through APIs. * Prefer strongly typed models over `object`, `dynamic`, loosely typed dictionaries, or string-based contracts. +* Write null-safe code: enable nullable reference types where supported, model nullability accurately, and check nullable values before dereferencing them. Avoid null-forgiving operators unless a nearby invariant proves the value cannot be null. * Prefer concrete collection types for internal parameters, properties, and local APIs when the contract does not need abstraction. * Expose collection interfaces such as `IReadOnlyList`, `IEnumerable`, `IDictionary`, or `ICollection` only when their capability is part of an intentional boundary or public contract. * Choose collection types based on lookup, ordering, mutation, and iteration needs. Pre-size collections only when expected capacity is known and material.