Metalama Status Update, July-August 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:
- New code generation abilities:
- Generate new types
- Introduce or override constructors
- Switch statement builder
- Lambda statements and anonymous methods in T# templates
- New open-source, ready-made aspects:
- Observable for
INotifyPropertyChanged
- Command and DependencyProperty for WPF
- Immutable
- Observable for
- Performance improvements
- Dozens of smaller enhancements
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 aGetRef()
method returning a strongly-typedIRef<T>
. IRef<T>
now has anAs<TOut>()
method to up-type the reference.ExpressionFactory
enhancements:Null
andDefault
methods.- We added a method
IAttributeCollection.GetConstructedAttributesOfType<T>(): IEnumerable<T>
. - We added extension methods
ICompilation.GetDeclarationsWithAttribute()
. - We added extension methods
IAspectReceiver<ICompilation>.SelectDeclarationsWithAttribute()
andIValidatorReceiver<ICompilation>.SelectDeclarationsWithAttribute()
for use in fabrics. - We added extension methods
IAttribute.GetArgumentValue()
andIAttribute.GetArgumentValue()
to easily get arguments by name. - The
TypedConstant
struct now implementsIEquatable<TypedConstant>
. - When a
TypedConstant
represents an array, theValue
property now returns the “user” array, e.g.,int[]
orobject[]
, instead of anImmutableArray<TypedConstant>
.
Testing experience
- New
TestContext.WithExecutionContext()
method added, allowing the use of classes likeExpressionFactory
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!
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