A shared passion
for clean code.

Metalama logo

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:

Replaced by the body ofthe target method.Replaced by the name of the target 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.

One way to apply an aspect to a target declaration is to use themas a custom attributes.

3b. Apply Aspects in Bulk

Alternatively, you can apply aspects in bulk using compile-time LINQ-like code.

This method works like a compile-time entry point to your project. It runs in thecompiler and in the IDE.Select targeted code withLINQ-style queries.Here we're adding an aspectbut we could also add some archiectural constraint.

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.

This is the original method body,introduced by meta.Proceed().This is the method name,from meta.Target.Method.The green code is the onegenerated from the template.

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.


  • T# Templates

    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

    Override Anything: In contrast to proxy-based AOP frameworks, Metalama is not confined to interfaces and virtual methods.

  • Aspect Inheritance

    Aspect Inheritance: Automatically propagate aspects to child classes by annotating parent classes—across projects as well.

  • Fabrics

    Fabrics: Create compile-time entry points for adding aspects or validating code within your project.

  • Intellisense

    Intellisense: Access aspect-introduced code in real-time, eliminating the need for recompilation.

  • Diagnostics

    Instant Diagnostics: Receive immediate error and warning notifications directly within the editor, courtesy of aspects.

  • Diff Preview

    Diff Preview: Effortlessly compare source and transformed code directly within Visual Studio.

  • CodeLens Integration

    CodeLens: Quickly identify applied aspects within the editor, even when it isn't apparent from the source code.

  • Code Fixes

    Custom Fixes & Suggestions: Craft team-specific code fixes that are linked to diagnostic notifications.

  • Syntax Highlighting

    Syntax Highlighting: Effortlessly differentiate meta code through T# color-coding.

  • Debugging Flexibility

    Debugging Flexibility: Choose whether to step into the transformed code or stick to the source code during debugging.

  • Testing Framework

    Testing Framework: Conveniently test aspects on various target declarations. The framework integrates with the Visual Studio test runner.

  • Querying Interactively with LinqPad

    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

    No Vendor Lock-In: Export transformed code easily, enabling a smooth transition back to vanilla C# if needed.

  • Roslyn Extensibility

    Extensible with Roslyn: Bypass Metalama's limitations by writing transformations directly using Roslyn.

  • Open-Source Extensions

    Open-Source Extensions: Benefit from a wide variety of published extensions and samples, all under open-source licenses.

  • Multi-Platform Compatibility

    Multi-Platform: Works with Visual Studio, Visual Studio Code, Rider, and almost all build servers. Targets any .NET Standard 2.0-compatible platform.