Metalama 1.0 / / Metalama Documentation / Conceptual Documentation / Creating Aspects

Creating Aspects

This chapter explains how to build your own aspects. If you only want to learn how to use aspects written by others, you can skip this chapter in first reading. However, we suggest you to come back here if you want to understand better the "magic" behind Metalama.

Benefits

  • Boilerplate elimination. When you use the code transformation abilities of aspects to generate boilerplate at compile time, you get the following benefits:

    • Less code to write. You no longer need to write repetitive code because it is generated by your aspect.
    • Clean and readable code. This is even more important. Your source code is cleaner, with fewer lines of code for the same feature. The business logic clearly stands because it is not littered by boilerplate.
    • Fewer bugs. Since there is less code, there is also fewer bugs.
    • Deduplication. Cross-cutting patterns are defined in one place, so if you need to change them or fix them, you don't need to fix it all around your code base.
  • Code validation. You can use aspects to create custom attributes that validate code. For details and benefits, see Validating Code.

  • Code fixes and refactorings. You can use aspects to suggest code fixes and refactorings. For details, see Building IDE Interactions.

In this chapter

This chapter is composed of the following articles:

Section Description
T# Template This article explains how to create dynamic code templates.
Transforming Code This section explains how to create aspects that perform advanced code modifications using the complete API.
Reporting and Suppressing Diagnostics This article explains how to report or suppress errors, warnings and information messages.
Injecting Dependencies Into Aspects This article describes how an aspect can use a dependency and pull it from the container.
Building IDE Interactions This article explains how to create live templates, code fixes and refactorings.
Adding Child Aspects This section explains how an aspect can add other aspects, and how child aspects can know about their parents.
Aspect Inheritance This section explains how to automatically make an aspect apply to all declarations derived from its direct targets.
Ordering Aspects This article describes how to order aspect classes so that the order of execution is correct when several aspects are applied to the same declaration.
Exposing Configuration This article explains how an aspect can expose and consume configuration properties or a configuration API.
Testing Aspects This section explains how to test aspects.
Debugging Aspects This article explains how to debug aspects.