A Shared Passion
for Clean Code.
A modern C# meta-programming framework to improve your code quality and productivity.
- 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.
- Leverage a robust open-source ecosystem featuring a mix of community-contributed and professionally supported aspects and architectural rules for your immediate use or customization.
What are the costs associated with boilerplate and architecture erosion?
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.
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.
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.
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 review 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
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:
It may seem simplistic, and it is. Dozens of open-source aspects are available 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.
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 seamlessly merges the aspect template with your business code. This process is executed on the fly to maintain the clarity of your source code.
Aspects can report errors and suggest code fixes. However, elaborating on this would exceed the scope of a basic Hello, world! example.
T# Templates: Leverage the power of T#, a template language devoid of markup, compatible with C# syntax, and supportive of Visual Studio syntax highlighting.
Override Anything: Unlike proxy-based AOP frameworks, Metalama is not restricted to interfaces and virtual methods.
Aspect Inheritance: Enable automatic propagation of aspects to child classes by annotating parent classes—this feature extends across projects.
Fabrics: Establish compile-time entry points for adding aspects or validating code within your project.
Intellisense: Gain real-time access to aspect-introduced code, eliminating the need for recompilation.
Instant Diagnostics: Receive immediate error and warning notifications directly within the editor, thanks to aspects.
Diff Preview: Conveniently compare source and transformed code directly within Visual Studio.
CodeLens: Easily identify applied aspects within the editor, even when it's not evident from the source code.
Custom Fixes & Suggestions: Develop team-specific code fixes associated with diagnostic notifications.
Syntax Highlighting: Easily distinguish meta-code using T# syntax hightlighting.
Debugging Flexibility: Decide whether to step into the transformed code or adhere to the source code during debugging.
Testing Framework: Test aspects on various target declarations with ease. The framework integrates seamlessly with the Visual Studio test runner.
Interactive Querying: Leverage the Linqpad driver to query your codebase interactively like a database, and analyze the behavior of your aspects and fabrics.
No Vendor Lock-In: Easily export transformed code, facilitating a smooth transition back to vanilla C# if required.
Extensibility with Roslyn: Overcome Metalama's limitations by scripting transformations directly using Roslyn.
Open-Source Extensions: Avail of a wide array of published extensions and samples, all under open-source licenses.
Multi-Platform Compatibility: Compatible with Visual Studio, Visual Studio Code, Rider, and most build servers. Targets any .NET Standard 2.0-compatible platform.