Records and Interfaces: Here Be Dragons

When it comes to C# types—classes, structs, and records—understanding the difference between value and reference equality is crucial. Each type behaves differently in terms of equality checks, inheritance, and how they manage their internal state. However, things can get tricky when you introduce interfaces into the mix, particularly when dealing with records.

Continue reading “Records and Interfaces: Here Be Dragons”

Optimal usage of Global Usings

I have a solution with ~40 projects, built during many years with wild usings that I wanted to clean up. The global usings feature, introduced in with C# 10.0 and .NET 6 (nov21) to simplify and reduce the repetition of commonly used namespaces throughout a project.

The question I have is, how do I ‘get’ the most commonly used namespaces and how do I do that at scale.

Continue reading “Optimal usage of Global Usings”

Value Objects in C# – Part 2

2. Choosing the property modifiers

Property setters in C# play a crucial role in defining how you can interact with class and record members. The set, init, and get-only accessors offer different levels of mutability and initialization control, crucial for both mutable and immutable object design. There are a couple of options out there, which one to choose?

Continue reading “Value Objects in C# – Part 2”