Categories
.NET .NET 10 .NET MAUI Android Blazor C# Code Deep Dive Desktop Developer Getting Started Hybrid iOS Learn Mobile Preview Visual Studio VS Code Web What's New Windows Xamarin Xamarin.Forms

What’s New in C# 14 – Extension Members – A Comprehensive Guide

Introduced in C# 3.0, extension methods are a valuable feature for external types, especially when those types are sealed, such as string.

Roughly two decades later, C# has now finally unveiled support for extending everything.

With the release of .NET 10 Preview 3 (C# 14), it is now possible to define static methods, instance properties, and static properties too. Support for other members will be incorporated in future releases.

Syntactically, an extension method should be defined within a top-level static class. The type of its first mandatory parameter, the one qualified with the this keyword, determines the type being extended. Henceforth, this will be referred to as the receiver type.

All standard query operators of LINQ are defined as extension methods. They are defined in the Enumerable static class within the BCL (in the System.Linq namespace).

For example, the Where extension method applies to all types that implement IEnumerable<T>. Validations and optimizations aside, the typical implementation is as outlined below.

Categories
.NET .NET 8 .NET 9 .NET MAUI Android Blazor C# Code Desktop Developer General Getting Started Hybrid iOS macOS Made Easy MVVM NuGet Preview Toolkit Visual Studio VS Code What's New Windows Xamarin Xamarin.Forms

MVVM Toolkit v8.4: Custom Access Modifiers for Partial Properties – How To

This article is part of the MVVM – Made Easy series, with a focus on the initial preview release of v8.4 of the CommunityToolkit.Mvvm (aka Microsoft MVVM Toolkit) NuGet package, which includes support for Partial Properties.

Update as of Dec 2024: The v8.4 stable release is now available. For further details, please refer to this blog post.

Here are the links to other articles in this series.

Support for Partial Properties is one of most sought after features in the MVVM toolkit as it allows to define custom access modifier for property accessors and makes code more readable. The need for an analyzer to track the usage of a field instead of a (generated) property is no longer necessary.