Build Robust and Maintainable Applications With Less Code.

Metalama logo

The simplest and most powerful code generation and validation toolkit for C#.

  • 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.
  • Excel with large, complex, or old codebases. Metalama does not require you to change your architecture. Beyond getting started, it's at scale that it really shines.

What are boilerplate and architecture erosion costing you?

A Total Waste of Time


Manually writing boilerplate is not only boring and frustrating, but also a total waste of your time. Why manually do what a machine can accomplish more efficiently and swiftly?

Although allowing architecture to erode initially saves time, as it progressively accumulates, it makes everyone on the team less productive.

Excessive Complexity


If your business logic is cluttered with boilerplate, the source code becomes so complex that it's no longer comprehensible.

As the source code diverges from the original architecture, more exceptions to the rule are introduced, increasing the conceptual complexity of the source code.

Avoidable Defects


Boilerplate is often riddled with bugs because it's created by copy-paste programming and is largely untested. Production-readiness features such as logging or caching are neglected because they are too costly to build without the appropriate tools.

As the complexity of your codebase increases, its overall quality suffers: end-users encounter bugs and performance deteriorates.

Expensive Maintenance


As both boilerplate and architectural erosion contribute to increasing complexity, small changes to your application become increasingly expensive. A larger refactoring becomes completely unfeasible, necessitating a complete rewrite of your entire codebase.

Intelligent use of meta-programming could extend the lifespan of your codebase by several years.

Our Approach: Simple, Robust Meta-Programming

Meta-programming is the practice of writing code that generates, modifies, or validates other code. This approach streamlines repetitive tasks and makes code reviews more efficient.

With a focus on simplicity and safety, we have reimagined aspect-oriented programming (AOP) for modern .NET applications.

Aspects and fabrics are distinct C# classes that execute within the compiler or the IDE and perform the following tasks:

  • Generate repetitive code at compile-time, ensuring your source code remains crystal clear;
  • Verify source code against patterns and architectural rules, reporting errors in real-time;
  • Suggest code fixes and refactorings, and provide guidance to developers.

Do it by your rules. Create your own code templates and verification rules easily and safely.

Show Me Code!
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 to enhance your 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 may seem simplistic, and it is. Dozens of open-source aspects are available on Metalama Marketplace for you to use or modify.

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 Using a Fabric

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

A fabric is a specific kind of class that executes at build time or within the IDE. Unlike aspects, fabrics do not need to be applied to anything. They serve as their own entry points.

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 seamlessly merges the aspect template with your business code. This process is executed on the fly to maintain the clarity of your source code.

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.

Show Me More!
How Can I Validate Architecture?

1. Add the Architecture Package to Your Project

Add the Metalama.Extensions.Architecture package to your project.

2. Add a Fabric Class

For instance, let's verify that internal members of the current namespace are only utilized within that namespace or from a unit test.

Validation fabric

3. Your Code Is Now Validated In Real Time

A warning is now reported directly in the editor whenever you attempt to access an internal of a checked namespace from an unauthorized location.

Validation results

Will I Still Understand My Code?

We believe that you will comprehend the business meaning of your code even better than before since it will not be cluttered with boilerplate. When the time comes to read the fine print, Metalama shows you the exact generated code. You can even debug it!

  • CodeLens Integration

    CodeLens: Effortlessly identify applied aspects within the editor, even when it's not evident from the source code.

  • Diff Preview

    Metalama Diff: Conveniently compare source and transformed code directly within Visual Studio.

  • Debugging Flexibility

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

  • Syntax Highlighting

    Syntax Highlighting: Distinguish meta-code easily using T# syntax highlighting.

  • Querying Interactively with LinqPad

    Interactive Querying: Utilize the Linqpad driver to query your codebase interactively, similar to a database, and analyze the behavior of your aspects and fabrics.

Delight Your Development Team

By harnessing the power of aspects and fabrics, coding architects and senior developers can act as force multipliers for the rest of the team. Metalama provides the tools to create a delightful development experience for the team, tailored to your project.

  • Diagnostics

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

  • Code Fixes

    Custom Fixes & Suggestions: Develop team-specific code fixes associated with diagnostic notifications.

  • Testing Framework

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

  • Aspect Inheritance

    Aspect Inheritance: Enable automatic propagation of aspects to child classes by annotating parent classes. This feature extends across projects.

  • Intellisense

    Intellisense: Gain real-time access to aspect-introduced code, eliminating the need for recompilation.

  • Multi-Platform Compatibility

    Multi-Platform Compatibility: Compatible with Visual Studio, Visual Studio Code, Rider, and most build servers. Targets any .NET Standard 2.0-compatible platform.

We've Got You Covered

We've been there before. Metalama has been developed by a team with over 100 years of cumulative programming experience. This team has been supporting PostSharp, Metalama's predecessor, for more than 15 years.

  • No Vendor Lock-In

    No Vendor Lock-In: This feature allows for easy exportation of transformed code, facilitating the transition back to vanilla C# if necessary.

  • Roslyn Extensibility

    Extensibility with Roslyn: Metalama's limitations can be overcome by scripting transformations directly using Roslyn.

  • Open-Source or Source-Available

    Open-Source or Source-Available: It is possible to step into Metalama's code under a source-available license. Extensions and aspect libraries are open source.