Project "Caravela" 0.3 / / Caravela Documentation / Conceptual Documentation / Creating Aspects / Creating a Live Template

Creating a Live Template

A live template is a custom Quick Action available in the code editor in the lightbulb or screwdriver menu along other code fixes or refactoring actions offered by the IDE. For details about consuming live templates, see Using Live Templates.

Live templates are built with the Caravela aspect framework, but instead of being executed at compile time by the compiler on intermediate code, they are applied in the editor and modify your source code.

Note

A fundamental characteristic of an aspect is that it is applied at compile time and does not affect your source code. Therefore, a live template cannot be named an aspect, even if it is built with the aspect framework. To avoid confusion, we suggest not to refer to live templates as aspects in your communications.

To build a live template

  1. Build an aspect class as usually, with the following differences:

    • The aspect class does not need to be derived from System.Attribute.
    • The implementation should pay more attention to generate idiomatic C# code.
    • Diagnostics reported by the aspect will be ignored.
    • Aspect ordering and requirements will be ignored.
  2. Override the BuildAspectClass method and set the IsLiveTemplate property to true.