A shared passion
for clean code.
A modern Roslyn-based meta-programming framework to improve your code quality and productivity in C#.
Metalama is the only C# code quality & productivity tool
that allows you to:
- Write and maintain less code by eliminating boilerplate, generating it dynamically during compilation, typically reducing code lines and bugs by 15%.
- Validate your codebase against your own rules in real-time to enforce adherence to your architecture, patterns, and conventions. No need to wait for code reviews.
- Provide coding assistance straight from the IDE with bespoke code fixes and save time on hesitations, documentation lookups, and typing.
Hello, world!
How Does It Work?
1. Add a Package to Your Project
Add the Metalama.Framework
package to your project.
Optionally, you can install Metalama Tools for Visual Studio for an enhanced development experience.
2. Create an Aspect Class or Use an Open-Source One
Aspects are meta classes that transform code using simple C#-based templates. They can also report warnings and errors or suggest code fixes.
Here is an aspect that automatically adds logging to a method:
It looks simplistic, and it is. Dozens of open-source aspects are available for you to use or fork.
3a. Add Aspects to Your Business Code One at a Time
You can apply each aspect individually using a custom attribute.
3b. Apply Aspects in Bulk
Alternatively, you can apply aspects in bulk using compile-time LINQ-like code.
4. You're Done!
Upon compilation, Metalama merges the aspect template with your business code, doing so on the fly to ensure your source code remains crystal-clear.
Aspects can also report errors and suggest code fixes, although covering this in detail would be beyond the scope of a simple Hello, world! example.
Features
-
T# Templates: Utilize the capabilities of T#, a markup-free template language compatible with C# syntax that also supports Visual Studio syntax highlighting.
-
Override Anything: In contrast to proxy-based AOP frameworks, Metalama is not confined to interfaces and virtual methods.
-
Aspect Inheritance: Automatically propagate aspects to child classes by annotating parent classes—across projects as well.
-
Fabrics: Create compile-time entry points for adding aspects or validating code within your project.
-
Intellisense: Access aspect-introduced code in real-time, eliminating the need for recompilation.
-
Instant Diagnostics: Receive immediate error and warning notifications directly within the editor, courtesy of aspects.
-
Diff Preview: Effortlessly compare source and transformed code directly within Visual Studio.
-
CodeLens: Quickly identify applied aspects within the editor, even when it isn't apparent from the source code.
-
Custom Fixes & Suggestions: Craft team-specific code fixes that are linked to diagnostic notifications.
-
Syntax Highlighting: Effortlessly differentiate meta code through T# color-coding.
-
Debugging Flexibility: Choose whether to step into the transformed code or stick to the source code during debugging.
-
Testing Framework: Conveniently test aspects on various target declarations. The framework integrates with the Visual Studio test runner.
-
Querying Interactively: Utilize the Linqpad driver to interactively query your codebase like a database, and analyze the behavior of your aspects and fabrics.
-
No Vendor Lock-In: Export transformed code easily, enabling a smooth transition back to vanilla C# if needed.
-
Extensible with Roslyn: Bypass Metalama's limitations by writing transformations directly using Roslyn.
-
Open-Source Extensions: Benefit from a wide variety of published extensions and samples, all under open-source licenses.
-
Multi-Platform: Works with Visual Studio, Visual Studio Code, Rider, and almost all build servers. Targets any .NET Standard 2.0-compatible platform.