Coding StandardsTypes, Records, and Modern C#
Types, Records, and Modern C#
Choosing the right type shape and modern C# language features to express it cleanly.
These standards cover how to choose between class, record, and struct; how to model closed
sets of variants; and how to use modern C# (records, pattern matching, extension members,
collection expressions) to express intent without boilerplate. Apply them whenever defining a new
type or deciding how a value should be represented.
- Add Record Factories via Extension Members
- Approximate F# Discriminated Unions With Sealed Records
- Choose class, record, or struct Based on Semantics
- Choose the Right Record Kind by Required Equality and Storage Semantics
- Choose the Right Sum-Type Representation for Closed Sets of Variants
- Closed Shapes, No Nulls: F# Discipline in C#
- Model Discriminated Unions as Sealed Record Hierarchies
- Persist a C# Union Type in EF Core via a Shadow Complex Property
- Prefer Closed Records + Functional Map Over OO Interfaces
- Prefer
params IReadOnlyList<T>Overparams T[] - Use C# 14 Extension Members for Context-Specific Views
- Use Modern C# Syntax to Remove Boilerplate
- Use Property Patterns and Tuple Switch Expressions
- Use var by Default
- Validate Records at Construction With a Nullable Factory
- Wrap Measured Quantities in Dedicated Types