BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News .NET Community Toolkit 8.1 Released

.NET Community Toolkit 8.1 Released

Bookmarks

Recently Microsoft released .NET Community Toolkit 8.1. This new release contains performance improvements to the MVVW Toolkit source generators. There are also new features such as custom attributes for ObservableProperty, MVVM Toolkit analyzers, IObservable<T> messenger extensions and support for .NET 7 and C# 11.

The previous (8.0.0) version was a collection of helpers and APIs that facilitate using patterns like MVVM independently of the underlying platform. Version 8.1 includes changes impacting various areas such as performance or improving code readability. All of the features introduced were already present in the preview version.

The community had requested supporting custom attributes for ObservableProperty. Previously, this could only be set manually for the source-code generator of the MVVM toolkit. In order to implement this feature in the new version, the Microsoft team decided to use the existing property: - it is a syntax in C# to allow developers to mark attributes for propagation to generated properties. This solution offers certain advantages: by using the built-in C# syntax, the property does not require additional attributes. In addition, this solves the problem of annotating attributes, which can only apply to properties and not fields.

The new version of the .NET Community Toolkit provides developers with more targeted support in optimising the use of the MVVM Toolkit. The source generators will now use the Roslyn 4.3 target, so they can enable some of the more optimised APIs if the host supports them. This is automatically enabled when referencing the MVVM Toolkit. The other thing is to switch generators to the new high-level Roslyn API to match attributes, which improves the performance of generators run on the basis of specific attributes.

Developers also moved almost all diagnostics to diagnostics analyzers, which reduces overhead while typing. This improves all incremental models and pipelines to also reduce overall memory allocation.

Another new feature is how to bring together the functionality provided by the messenger APIs in the MVVM toolkit. This is now supported with the new IObservable<T> extensions for the IMessenger interface. The extensions can be used as follows:

IObservable<MyMessage> observableMessage = Messenger.CreateObservable<MyMessage>();

This extension will create an IObservable<T> object that can be used to subscribe to messages and dynamically respond to them.

.NET Community Toolkit 8.1 also provides the .NET 7 TFM platform to the HighPerformance package and several changes to take advantage of the new features of the C# 11 language, particularly the ref fields. It is possible to declare ref fields inside a ref struct. Additionally, the runtime is able to fully define Span<T> using the C# type system.

In addition to the official release post, Sergio Pedri, .NET engineer at Microsoft, also wrote a comment on Reddit about adding the Roslyn multi-targeting:

Hopefully, the experience in Rider is better now - I added Roslyn multi-targeting in this new release and it's possible that wasn't playing too well with Rider. But now there's also another custom .targets in the MVVM Toolkit that manually handles multi-targeting if the target host doesn't support it, so maybe that helps? Anyway hopefully the experience outside of Visual Studio is smoother now.

Aathif Mahir, a .NET developer, commented on Twitter in the thread about the .NET Community Toolkit 8.1 announcement:

Those who are outside of Windows or .NET ecosystem don't know how powerful .NET Community Toolkit is and how much time it saves for developers, really appreciate the whole community that contributed to the toolkit and @SergioPedri for super awesome Source Generators.

The entire changelog of this release is available on GitHub.

 

About the Author

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT