Skip to content
| Marketplace
Sign in
Visual Studio>Tools>Metalama + PostSharp
Metalama + PostSharp

Metalama + PostSharp

PostSharp Technologies

postsharp.net
|
522,413 installs
| (588) | Free
A unified UI for Metalama and PostSharp, two code generation and validation toolkits for .NET. They help you deliver clean code, without boilerplate, strictly adhering to architecture.
Download

Metalama and PostSharp: Code Generation and Verification Toolkits for C#

This extension supercharges your development experience with a unified UI for Metalama and PostSharp.

Why Choose Metalama or PostSharp?

Metalama and PostSharp equip you with the tools to construct robust and maintainable applications with less code.

With these tools in your arsenal, you can:

  • Reduce your codebase by eradicating boilerplate and generating it dynamically during compilation, typically reducing your code lines and potential bugs by 15%.
  • Enforce your codebase integrity by real-time verification against your specific rules, ensuring adherence to your architectural patterns and conventions. No more waiting for code reviews!

Metalama is our flagship product, designed for the new .NET stack and built upon Roslyn. It offers full integration with Visual Studio and all its new features.

PostSharp is our original product, built on MSIL rewriting. It continues to receive active maintenance and support for new versions of .NET and C#.

Metalama or PostSharp: Which One to Use?

For all new projects, we recommend Metalama.

How Metalama Works

1. Add a Package to Your Project

Add the Metalama.Framework package to your project.

2. Develop an Aspect Class or Utilize an Open-Source One

Aspects are meta-classes transforming code using simple C# templates. They can also flag warnings and errors or suggest code fixes.

Here's an aspect that automatically introduces logging to a method:

Logging Aspect

It may seem overly simple, because it is the most trivial example! Numerous open-source aspects are readily available on Metalama Marketplace for your usage or modification.

3a. Apply Aspects to Your Business Code One at a Time

You can apply each aspect individually using a custom attribute.

Adding Aspect As Attribute

3b. Apply Aspects in Bulk

Or, you can apply aspects en masse using compile-time LINQ-like code.

Adding Aspect With a Fabric

4. Voila! You're All Set!

Upon compilation, Metalama seamlessly merges the aspect template with your business code. This process is executed on the fly, ensuring your source code remains clean and clear.

Generated Code

Aspects can also flag errors and recommend code fixes. However, exploring this extends beyond the scope of a basic Hello, world! example.

What Features Does This Extension Add?

While both Metalama and PostSharp are primarily distributed as NuGet packages and don't require an IDE extension, this extension enhances the development experience with the following features:

Metalama Diff

Quickly compare your source code with the generated code.

Metalama Diff

CodeLens

Get instant hints when an aspect is influencing your code.

Metalama Diff

Aspect Explorer

Discover the aspects available in the current solution and understand their impact on your code.

Aspect Explorer

T# Syntax Highlighting

T# is Metalama's C#-to-C# template language. It's 100% C#-compatible, but the syntax highlighting feature helps you differentiate between code running at compile time and code running at runtime.

Syntax Highlighting

PostSharp Debugging Helper

This extension also includes a debugging helper for PostSharp-based projects.

What More Can You Do With Metalama?

Metalama is more than just simple aspects. It's a whole universe waiting to be explored.

Validate Architecture

You can easily express architecture in your code and have it enforced in real time right from the editor. In this example, we don't want internals of the current namespace to be accessed from a different namespace except for tests.

Validate Architecture

Report Errors and Warnings from Aspects

Any aspect can report errors or warnings when a violation is detected.

Report Diagnostics

Suggest Code Fixes

Aspects can provide code refactorings and attach code fix suggestions to errors and warnings.

Suggest Code Fixes

Use Generated Code From Source Code

Any code generated by an aspect is visible from Intellisense and can be used in source code.

Use Generated Code From Source Code

Divorce

Metalama gracefully accepts when it's time to part ways and makes the breakup process as smooth as possible. With the metalama divorce command, there's no need for a lengthy, handwritten code separation. It's like a considerate partner injecting the generated code right into your source code, preserving your sanity and your time.

Divorce

Test Your Aspects

Metalama comes with a testing framework to ensure you prove your aspects before distributing them to your team.

Test Your Aspects

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft