Metalama Status Update, May 2024
Have you ever experienced that surprising feeling when, looking at day-to-day progress during standup meetings, you lament the lack of progress, but when the time comes for a monthly digest, you’re amazed by the total achievements? This month is no exception. We’ve seen lots of releases and new features, and a rebirth of our marketing effort after a 3-year hiatus.
PostSharp 2024.0 Is Now LTS
We’ve promoted the PostSharp 2024.0 release to Long-Term Support status. This version will be supported until January 4, 2029, or 1 year after a future version is promoted to LTS. Support for the previous LTS, PostSharp 6.10, will end on May 1, 2025.
Bugfixing Releases
We’ve published several bug-fixing releases for Metalama 2024.0 and 2024.1 and PostSharp 6.10, 2024.0, and 2024.1.
For details, please refer to the Metalama changelogs or the PostSharp release notes.
Work in Progress in Metalama 2024.2
We’ve made a lot of progress in Metalama 2024.2, which is now almost code-complete. Here are the new features and improvements this month.
Introduction of classes and constructors
This is the most significant feature since we released 2023.0 last year!
It’s now possible to introduce whole classes by using the IAdviceFactory.IntroduceClass
method. This method returns an IAdviser<INamedType>
, which you can then use to add members to the new type.
We’ve added the IAdviceFactory.IntroduceConstructor
and IAdviser<INamedType>.IntroduceConstructor
extension method to introduce a constructor into an existing or new type.
There are still some limitations we are working on: you can currently only add nested types, but you cannot add top-level types to a namespace.
To see class introduction in action, see our Memento example and its generated code.
By the way, IAdviser<T>
and its extension methods are the new way to add advice to a declaration. The IAspectBuilder<T>
interface derives from IAdviser<T>
. For instance, if you have an IAspectBuilder<INamedType>
, you can do builder.IntroduceMethod(...)
instead of builder.Advice.IntroduceMethod( builder.Target, ...)
.
Code model improvements
- We’ve added support for lambda statements and anonymous methods of known scope, i.e., either run-time or compile-time (the scope can be coerced using
meta.RunTime
ormeta.CompileTime
when it’s not obvious from the context). Lambda expressions returningdynamic
are not supported and won’t be. Single-statement lambdas (e.g.,() => { return 0; }
) are transparently simplified into expression lambdas (e.g.,() => 0
). - We’ve added the
Promise<T>
class andIPromise<T>
interface to represent results that are not available yet. This mechanism allows resolving chicken-or-egg issues when introducing members when a template must receive a reference to a declaration that has not been introduced yet. APromise<T>
can be passed as an argument to a template, which receives it on a parameter of typeT
. - We’ve added the
IMethodInvoker.CreateInvokeExpression
method to generate anIExpression
that represents a method invocation. It can be called outside of a template context. - We’ve added the
IConstructorInvoker
interface with methodsInvoke
andCreateInvocationExpression
, so it’s now possible to easily create object-creation expressions.
Code formatting improvements
- Where applicable, redundancies in member access expressions are eliminated (e.g.,
this.X
orMyType.Y
becomesX
orY
). - Non-extension calls to extension methods in templates are transformed into extension calls. This is useful because extension methods cannot be called on dynamic types. For instance, the C# code
LoggerExtensions.LogInformation( meta.This._logger, "Hello" )
would compile to_logger.LogInformation( "Hello" )
. -
The discard parameter
_
, when used in templates, is no longer renamed to__1
,__2
, and so on. - The performance of whole-project output code formatting has been improved. Note that code formatting is disabled by default so it should not affect your standard builds, but
LamaDebug
builds should be faster.
Observable and XAML aspects
- We’ve refactored the
[Observable]
,[Command]
, and[DependencyProperty]
aspects, which are now almost RTM-ready. This work triggered many of the improvements listed above.
The Metalama logo got two awards!
Our logo received two gold medals this month, one from the Indigo Award and the second from the Titan Brands. Congratulations to the logo designer James Barnard for a wonderful creation. I knew James was an award-winning designer, but I didn’t expect him to win an award with our logo.
Timeless .NET Engineer series
We’ve launched the Timeless .NET Engineer blog and newsletters.
The goal of this series is to educate .NET developers about building robust and maintainable applications, with clean code. Metalama is often mentioned as a possible solution, but none of the articles will be product-centric.
This month, we released two articles:
You can subscribe to this newsletter here.
We’re welcoming guest authors. Don’t hesitate to contact us.
Moreover, now that the ChatGPT frenzy has attenuated, we’re departing from AI-generated images on this blog, and opting for hand-crafted minimalistic illustrations instead. I chose to stick with playful seasonal images for the monthly images, contrasting with the very seriousness of our business, and hope you will enjoy.
Roadmap
We will continue working on 2024.2 in June, finishing the work on type introductions. Two features will make it to 2024.2: introducing types into a namespace (instead of nesting it into another type), and an extension to the Aspect Explorer UI to display generated files. We still have to document the [Observable]
, [Command]
and [DependencyProperty]
aspects. Therefore, we plan to have a GA release by the first half of July.
Most of the summer should be dedicated to completing the gaps left in type introductions (such as introducing structs, records, primary constructors), to fixing bugs and, of course, taking some time off with our families. Then, by September or October, we’ll get prepared for .NET 9.
At the same time, we’ll steam up our marketing effort and publish more general articles.
Conclusion
We’re really excited by the upcoming Metalama 2024.2 release, which closes the last feature gaps with Roslyn source generators and opens the door to very productive aspects. Stay tuned for updates, and don’t forget to share any feedback you may have on Slack.