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.

  • Online sandboxTOCInstant SearchUnit-tested snippets

    Exceptional Documentation: Metalama can be learned through our comprehensive documentation, which includes commented examples and an online sandbox. All examples are continually unit-tested for accuracy.

  • Optimal Performance

    Optimal Performance: Experience no run-time overhead with Metalama. The code you see is precisely the code that gets executed.

The Result: Clean, Concise Code
Adhering to Architectural Guidelines and Design Patterns.

Boosting Development Efficiency


Metalama streamlines software development by reducing code by 10-50%, thereby enabling developers to focus on meaningful tasks. It enhances job satisfaction by eliminating repetitive low-level code and frustrating reviews. Furthermore, it acts as a talent multiplier, empowering architects and senior developers to tackle architectural challenges. New team members can contribute effectively without being overwhelmed by low-level technical details.

Taming Code Complexity


The separation of technical details from business logic results in cleaner, more readable code, which allows team members to work more efficiently. Strict adherence to the initial architecture and design patterns reduces complexity, ensuring a manageable, well-structured codebase. This approach helps to prevent excessive rules and violations, whether unintentional or due to unwarranted creativity, thereby maintaining overall simplicity and integrity.

Elevating Application Reliability


Aspects enhance the readability and maintainability of the codebase by separating technical and business logic. Meta-programming promotes consistency and streamlines reviews, thereby reducing developer oversights and limiting unwanted creativity. Additionally, aspects improve software modularity, preventing duplication and enhancing reusability, adaptability, and efficiency.

Streamlining Maintenance


Metalama's ultimate advantage lies in reducing maintenance costs and extending the lifespan of the codebase. Given that maintenance accounts for 55%-95% of a software system's costs, maintaining low complexity is crucial for post-release team member productivity. Considering that developers spend approximately 70% of their time understanding code, maintaining simplicity significantly enhances the efficiency of the maintenance team.

How Does It Compare?

Metalama PostSharp Roslyn Plug-In Fody
Technology Roslyn MSIL Roslyn MSIL
Transformation of the compilation using low-level APIs
Yes Yes No Yes
Addition of behaviors to source code using simple custom aspects or templates
Yes Yes No No
Introduction of new members or interfaces and referencing them in the source code
Yes No Complex No
Analysis of the source code and reporting of warnings and errors in real-time
Yes Requires Rebuild Complex Requires Rebuild
Debugging and exporting of transformed code
Yes No N/A No

What's Holding You Back?

Can I achieve the same results with open-source tools?

->

You might be considering Roslyn analyzers, Roslyn code generators, or open-source IL tools.

However, Metalama is in a league of its own.

Metalama is Integrated. Metalama stands alone as the only tool that allows you to both generate code visible at design time and override hand-written code. To replicate what Metalama offers, you would need to juggle a combination of open-source tools that lack integration.

Metalama is Simpler. Meta-programming at the abstraction level of Roslyn or MSIL is intricate, demanding years of experience. When approached naively, low-level meta-programming can resemble hacking and can significantly amplify complexity, especially after the departure of the developer who implemented the meta-code.

Metalama is Engineered for Good Architecture. Metalama is designed to simplify development. It avoids offering hacks that render the code less predictable or comprehensible. Software development encompasses three cultures: hacking, science, and engineering. We identify with the last one while remaining mindful of the other two.

Metalama is a Complete, Well-thought-out Solution. Unlike alternatives that focus on the most common use cases and cut corners – for instance, by failing to properly implement async methods – Metalama goes the extra mile and incorporates enough extension points to ensure you never hit a dead end.


I'm concerned about losing control over my code.

->

Delegation is What You Actually Want. You want the machine to handle low-level, repetitive details, freeing up more of your time to focus on meaningful tasks.

You're Already Accustomed to This. Initially, people were apprehensive about losing control over performance when the industry transitioned from assembly language to C, and then to the managed, garbage-collected memory model of C# and Java. We've relinquished control over low-level details but have gained enormous productivity and reliability.

You're not completely losing control. Metalama offers numerous mechanisms to override default behaviors.

You can revert to the source code at any time. There is no vendor lock-in.


What if I am already using ReSharper, Rider, or CodeRush?

->

You can and should use both. We are also fans of refactoring tools.

Metalama reduces the amount of code. While refactoring tools help developers write code faster, they do not reduce the amount of code necessary to implement a feature.

Metalama simplifies the writing of custom rules and code fixes. Other refactoring tools often have more complex APIs.


Get started with Metalama.

More than 10% of all Fortune 500 companies have already chosen PostSharp.

Microsoft
Oracle
Intel
Amazon
Tesco
EBay
Comcast
Lufthansa
Bank of America
Deutsche Bank