This issue is self-sponsored. By supporting my work and purchasing my products, you directly help me keep this newsletter free and continue creating high-quality, practical .NET content for the community.Â
Thank you for the support đ Â
P.S. Iâm currently building a new course, Pragmatic .NET Code Rules, focused on creating a predictable, consistent, and self-maintaining .NET codebase using .editorconfig, analyzers, Visual Studio code cleanup, and CI enforcement.
The course is available for pre-sale until the official release, with early-bird pricing for early adopters. You can find all the details here.
With .NET 10 extension feature now you can define extension blocks for any type. It is shaping up to be one of the most exciting updates in recent years - and one of the most underrated gems is the new extension keyword introduced in C# 14 (Preview 3).
If you thought extension methods were powerful before, this takes things to a whole new level.
In this article, Iâll break down:
With the new syntax, you can define extension blocks for any type. These blocks allow:
Syntax:
public static class MyExtensions{ extension(TargetType instance) { public ReturnType PropertyOrMethod => ...; }Â extension static { public static ReturnType StaticHelper() => ...; }}
Letâs say youâre building a multi-tenant SaaS product. You need to:
The old way? Youâd create scattered static methods. The new way? One structured block with everything grouped and cached.
public static class MultiTenantHttpContextExtensions{ extension(HttpContext ctx) { private string? _tenantId; private Guid? _userId;Â public string TenantId => _tenantId ??= ctx.User.Claims.FirstOrDefault(c => c.Type == "tenant_id")?.Value ?? throw new UnauthorizedAccessException("Tenant ID missing");Â public Guid UserId => _userId ??= Guid.TryParse( ctx.User.Claims.FirstOrDefault(c => c.Type == "user_id")?.Value, out var id) ? id : throw new UnauthorizedAccessException("User ID invalid");Â public bool IsTenantAdmin => ctx.User.IsInRole("Admin") || ctx.Request.Headers["X-Tenant-Admin"] == "true";Â public string? GetHeader(string name) => ctx.Request.Headers.TryGetValue(name, out var value) ? value.ToString() : null; }Â extension static { public static string DefaultTenantId => "public";Â public static bool IsValidTenantId(string? id) => !string.IsNullOrWhiteSpace(id) && id.All(char.IsLetterOrDigit); }}
This approach brings:
Letâs say youâre working with a third-party DTO:
public class OrderDto{ public List<OrderItemDto> Items { get; set; } public string Status { get; set; }}
With new extensions, you can wrap domain logic around it without modifying the class:
public static class OrderExtensions{ extension(OrderDto order) { public decimal TotalAmount => order.Items.Sum(i => i.Quantity * i.PricePerUnit);Â public bool IsComplete => order.Status == "Completed";Â public int TotalItems => order.Items.Sum(i => i.Quantity); }}
Usage becomes clean and expressive:
if (order.TotalAmount > 1000 && order.IsComplete){ // Do something}

This isn't just a cosmetic change - it's a paradigm shift in how we organize logic.
Use this when youâre extending a type with multiple behaviors that feel like they belong together:
It keeps your logic close, clean, and cache-friendly - and once you start using it, you wonât want to go back.
The new extension keyword isnât flashy at first glance. But it solves a real pain point for developers who care about clean architecture, rich domain modeling, and maintainable code.
It gives us the power we didnât even know we were missing in C# - and itâs just the beginning of a new era of expressiveness.
Let me know if you'd like to see how I plan to use this in:
That's all from me today.
P.S. Follow me on YouTube.
Stop arguing about code style. In this course you get a production-proven setup with analyzers, CI quality gates, and architecture tests â the exact system I use in real projects. Join here.
Not sure yet? Grab the free Starter Kit â a drop-in setup with the essentials from Module 01.
Design Patterns that Deliver â Solve real problems with 5 battle-tested patterns (Builder, Decorator, Strategy, Adapter, Mediator) using practical, real-world examples. Trusted by 650+ developers.
Just getting started? Design Patterns Simplified covers 10 essential patterns in a beginner-friendly, 30-page guide for just $9.95.
Every Monday morning, I share 1 actionable tip on C#, .NET & Architecture that you can use right away. Join here.
Join 20,000+ subscribers who mass-improve their .NET skills with actionable tips on C#, Software Architecture & Best Practices.
Subscribe to the TheCodeMan.net and be among the 20,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.