Features

Metalama is PostSharp’s open-source patterns & architecture toolkit for C#, built on Roslyn. It specializes in code generation (including aspect-oriented programming) and code validation. Additionally, it allows you to create custom code fixes or refactorings.

To achieve the same results with raw Roslyn, you would need to combine four separate, low-level tools that don’t work together: source generators (which can only add code, never modify existing members), MSIL rewriters like Fody (which modify existing code, but after compilation, so the results aren’t visible to your source or IntelliSense), analyzers (to report diagnostics), and code-fix providers (to offer IDE fixes). Metalama replaces all four with a single high-level API in which generation, validation, and fixes cooperate. For instance, a validation rule can account for the code an aspect generated.

FeatureDescription
Code GenerationMetalama is the simplest and most capable code generation framework for C#. Where Roslyn source generators can only add code, its aspects also override, wrap, and compose over existing members, so you can express transformations no other Roslyn-based approach can, with generated code integrated with your hand-written code.
Code VerificationMetalama makes it easy to validate hand-written or AI-generated code in real time, reporting errors and warnings when rules are violated. Thanks to the architecture validation package, you can also verify dependencies between classes and namespaces.
Design-Time FeedbackMetalama provides real-time feedback as you type, eliminating the need to constantly rebuild to refresh your IDE. Unlike MSIL-based approaches, and thanks to its integration with Roslyn source generators, Metalama allows you to reference generated declarations from hand-written code.
Code Fix Toolkit Boost your team’s productivity by suggesting custom code fixes for any errors or warnings reported by your code verification logic.
Ready-to-Use Aspect LibrariesMetalama comes with many professionally built and tested aspects that you can pull from NuGet and start using immediately.
Visual Studio Tooling See how your code is affected by aspects directly in Visual Studio with Code Lens integration, Aspect Diff, and Aspect Explorer. Get syntax highlighting for T#, Metalama’s C#-to-C# template language.
Test FrameworksTest code generation patterns and the reporting of warnings and errors.
Transformed Code DebuggingChoose whether to step into the transformed code or stick to the source code during debugging. You can see exactly which code is executed.
Code Query APIQuery your code as a database and explore code references using LINQPad. Access the Metalama object model to diagnose how aspects and fabrics affect your code.
DivorceMetalama makes it easy to part ways when needed. Run the metalama divorce command to commit the generated code into your source code and return to Microsoft’s plain compiler.