.NET 7 Preview 5 Boosts Generic Math, Observability, More -- Visual Studio Magazine

2022-06-30 08:12:29 By : Mr. Xudong Li

Microsoft shipped the fifth preview of .NET 7 en route to a November debut, with improvements concerning generic math, observability and much more.

Generic Math is so important it warranted its own blog posts last year as a preview feature and last week. It helps .NET developers take advantage of static APIs, including operators, from within their generic code.

Or, as last week's post says: "Generic Math combines the power of generics and a new feature known as static virtuals in interfaces to allow .NET developers to take advantage of static APIs, including operators, from generic code. This means that you get all the power of generics, but now with the ability to constrain the input to number like types, so you no longer need to write or maintain many near identical implementations just to support multiple types. It also means that you get access to all your favorite operators and can use them from generic contexts. That is, you can now have static T Add<T>(T left, T right) where T : INumber<T> => left + right; whereas previously it would have been impossible to define."

Generic Math especially benefits API authors, helping them to simplify their codebase. Other developers will also benefit, though more indirectly, because consumed APIs will start to support more types without requiring all numeric types to be explicitly supported.

"In .NET 7 we have made improvements to the implementation and responded to feedback from the community," said Angelos Petropoulos, product manager for the .NET team, in a June 14 announcement post. He pointed to last week's post (linked above) for more information.

The goal of observability, meanwhile, is to help developers better understand the state of their applications as scale and technical complexity increases, said Petropoulos. The preceding link points to a 2021 post about OpenTelemetry .NET reaching version 1.0. OpenTelemetry is described as "a collection of tools, APIs, and SDKs. Use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) to help you analyze your software's performance and behavior." It encompasses:

The improvement in .NET 7 Preview 5 is to expose performant ActivityEvent and ActivityLink tags enumerator methods, which is explained here. The goal is to eliminate the need for reflection or casting and improve performance when accessing tags associated with an event or link.

"The exposed methods can be used in performance critical scenarios to enumerate the Tag objects without any extra allocations and with fast items access," Petropoulos said.

Regular expression functionality has also been improved, specifically concerning a new RegexGenerator source generator, which helps developers to statically generate regular expressions at compile time, thus improving performance, as explained in this post from last month. To help, in Preview 5 the team added a Roslyn analyzer and fixer:

Other highlights of Preview 5 include:

All of the above and much more is explained in greater detail in the announcement post, along with a bunch of other fixes, optimizations and other tweaks.

David Ramel is an editor and writer for Converge360.

Uno Platform has beaten Microsoft to the punch when it comes to multi-threading in WebAssembly, the tech behind Microsoft's client-side Blazor web-dev framework.

Microsoft's TypeScript programming language over the past few years has been steadily climbing the popularity rankings in Stack Overflow's huge annual developer survey, this year knocking off Java to crack the top five.

In the latest Visual Studio 2022 preview, developers can edit source code from within All-In-One Search results.

VMware announced a new Visual Studio toolkit for working with Kubernetes clusters, containers, microservices and other cloud-native tech in its Tanzu line of products.

Rust rules among programming languages used for WebAssembly projects, but Blazor (C#) is coming on strong.

Problems? Questions? Feedback? E-mail us.