Metalama 1.0 / / Metalama Documentation / Aspect API / Metalama.​Framework.​Fabrics

Namespace Metalama.Framework.Fabrics

This namespace allows you to add fabrics to your code. Like aspects, fabrics are executed at compile time. Unlike aspects, you do not need a custom attribute to add the fabric to your code. The only existence of the fabric in your code applies it to your code.

Fabrics can be applied to:

  • the current project: a project fabric is a type in the project that implements the ProjectFabric class,
  • all projects that reference the current project: a transitive project fabric is a type in the current project that implements the TransitiveProjectFabric class,
  • a namespace: a namespace fabric is a type in that namespace that implements the NamespaceFabric class,
  • a type: a type fabric is a nested type that implements the TypeFabric class,

Fabrics can:

  • add aspects to code,
  • register validators,
  • configure aspects (project fabrics only),
  • add advice to the current type (type fabrics only)

Class diagrams

Fabrics

classDiagram class Fabric { } class ProjectFabric { AmendProject(IProjectAmender) } class TransitiveProjectFabric { } ProjectFabric --|> Fabric : derives from TransitiveProjectFabric --|> ProjectFabric : derives from class NamespaceFabric { AmendNamespace(NamespaceAmender) } NamespaceFabric --|> Fabric : derives from class TypeFabric { AmendType(TypeAmender) } TypeFabric --|> Fabric : derives from

Amenders

classDiagram class IAmender { Project } class IDeclarationSelector { With() } IAmender --|> IDeclarationSelector : derives from class IDeclarationSelection { AddAspect() AddAnnotation() RegisterValidator() RequireAspect() } IDeclarationSelector --> IDeclarationSelection : creates class IProjectAmender { } IProjectAmender --|> IAmender INamespaceAmender --|> IAmender ITypeAmender --|> IAmender class INamespaceAmender { Namespace } class ITypeAmender { Type Advice : IAdviceFactory } ITypeAmender --> IAdviceFactory : exposes

Namespace member

Classes

Fabric

Allows adding aspects or analyzing a project, namespace, or type just by adding a type implementing this interface. You must not implement this interface directly, but ProjectFabric, NamespaceFabric, or TypeFabric.

NamespaceFabric

An interface that, when implemented by a type in a given namespace, allows that type to analyze and add aspects to that namespace.

ProjectFabric

An interface that, when implemented by a type in a project (under any name or namespace), allows that type to analyze and add aspects to that project.

TransitiveProjectFabric

An interface that, when implemented by a type in an assembly (under any name or namespace), allows that type to analyze and add aspects to any project that references this assembly. However, the AmendProject(IProjectAmender) method is not executed in the current project (you will need another class that does not implement TransitiveProjectFabric to amend the current project).

TypeFabric

An interface that, when implemented by a nested type in a given type, allows that nested type to analyze and add aspects to the parent type.

Interfaces

IAmender<T>

Base interface for the argument of AmendProject(IProjectAmender), AmendNamespace(INamespaceAmender) or AmendType(ITypeAmender). Allows to report diagnostics and add aspects to the target declaration of the fabric.

IFabricInstance

Represents an instance of a Fabric type including its TargetDeclaration.

INamespaceAmender

Argument of AmendNamespace(INamespaceAmender). Allows reporting diagnostics and adding aspects to the target declaration of the fabric.

IProjectAmender

Argument of AmendProject(IProjectAmender). Allows reporting diagnostics and adding aspects to the target project.

ITypeAmender

Argument of AmendType(ITypeAmender). Allows reporting diagnostics and adding aspects to the target declaration of the fabric.