Metalama Status Update, July-August 2024

by Gael Fraiteur on 30 Aug 2024

I hope those of you in the Northern Hemisphere had a wonderful and restful summer! Despite the annual slowdown, our development team didn’t stay idle. On the last day of July, we announced the GA of Metalama 2024.2, shipping some long-awaited features. In August, we mostly focused on bug fixes and minor features, all released in the 2024.2 branch.

Metalama 2024.2 GA

We released the first stable build of Metalama 2024.2 on July 29th. This release introduces the most-requested feature: the ability to generate new classes (previously, you could only introduce new members into existing classes). We also added new ready-made aspects. Here’s a summary of the new features:

After the GA, we primarily focused on fixing bugs, particularly in the design-time (i.e., editing) experience. A total of 32 bugs were fixed after the GA.

See all changelogs for details.

Post-release improvements in Metalama 2024.2

In addition to bug fixes, we also added a few minor features in Metalama 2024.2:

Decoupling aspects from attributes

It’s now easier to separate your aspect logic from the custom attribute. Several approaches are supported and documented here. This is made possible by the following new APIs:

  • Most interfaces derived from IDeclaration (e.g., IField, IMethod, …) now have a GetRef() method returning a strongly-typed IRef<T>.
  • IRef<T> now has an As<TOut>() method to up-type the reference.
  • ExpressionFactory enhancements: Null and Default methods.
  • We added a method IAttributeCollection.GetConstructedAttributesOfType<T>(): IEnumerable<T>.
  • We added extension methods ICompilation.GetDeclarationsWithAttribute().
  • We added extension methods IAspectReceiver<ICompilation>.SelectDeclarationsWithAttribute() and IValidatorReceiver<ICompilation>.SelectDeclarationsWithAttribute() for use in fabrics.
  • We added extension methods IAttribute.GetArgumentValue() and IAttribute.GetArgumentValue() to easily get arguments by name.
  • The TypedConstant struct now implements IEquatable<TypedConstant>.
  • When a TypedConstant represents an array, the Value property now returns the “user” array, e.g., int[] or object[], instead of an ImmutableArray<TypedConstant>.

Testing experience

  • New TestContext.WithExecutionContext() method added, allowing the use of classes like ExpressionFactory in compile-time unit tests.
  • You can now test your aspects in scenarios other than compile-time generation by specifying the @TestScenario test directive. The following additional scenarios are available: code fix, live template, and design-time preview.

Articles

This summer, we have published no fewer than six general .NET articles!

Five Ways To Add Caching To Your ASP.NET App The Singleton Pattern in C# Today Is Not Your Dad's One! The Memento Design Pattern in C#, Practically With Examples [2024]
Adding Serilog to ASP.NET Core: a practical guide Simplify Your .NET Aspire Caching With Metalama MemoryCache in C#: A Practical Guide

Roadmap

September is usually the time when Microsoft releases the first RC of their new .NET stack. We plan to focus on .NET 9 and C# 13 as soon as this happens, updating both PostSharp and Metalama in what will become the 2025.0 versions. Our objective is to publish RCs of both products soon after the GA of the new .NET stack – traditionally in November. We expect these new versions to be generally available in the very first days of 2025. The feature that will likely require most of our attention is the Roslyn interceptors.

You might experience issues if you update your projects to .NET 9 without updating to Metalama 2025.0, so we suggest you pin your .NET SDK version in global.json and limit rollforward to minor.

Conclusion

We released Metalama 2024.2, the most anticipated release with support for type introductions, on July 29th. In August, we focused on bug fixes. The design-time experience is much more comfortable than before, and we encourage everyone to update to the newest build.

Stay tuned for news on Metalama 2025.0 starting in September.

Happy meta-programming with Metalama!

-gael

This article was first published on a https://blog.postsharp.net under the title Metalama Status Update, July-August 2024.