Open sandboxFocusImprove this doc

Namespace Metalama.Framework.Fabrics

This namespace enables the addition of fabrics to your code. Similar to aspects, fabrics are executed at compile time. However, unlike aspects, fabrics do not require a custom attribute for integration into your code. The mere existence of the fabric in your code applies it to your code.

There are four types of fabrics, each applying to a different scope. All types of fabrics can add aspects and validators within their respective scopes. Type fabrics have the additional capability of adding advice to their scope, and project fabrics can set configuration options.

Kind Base Class Scope Abilities
Type Fabrics TypeFabric The containing type (type fabrics are nested types) and any member. Add aspects, advice, and validators.
Namespace Fabrics NamespaceFabric Any type in the namespace that contains the fabric type. Add aspects and validators.
Project Fabrics ProjectFabric Any type in the project that contains the fabric type or in any project. Add aspects and validators, and set configuration options. Project fabrics can be inherited from parent directories.
Transitive Project Fabrics TransitiveProjectFabric Any type in any project referencing the containing project. Add aspects and validators, and set configuration options.
Note

For enhanced design-time performance and usability, it is strongly recommended to implement type fabrics in a separate file and mark the parent class as partial.

Class diagrams

Fabrics

classDiagram

    class Fabric {

    }

    class ProjectFabric {
        AmendProject(IProjectAmender)
    }

    class TransitiveProjectFabric {
    }

    Fabric <|-- ProjectFabric : derives from
    ProjectFabric <|-- TransitiveProjectFabric : derives from

    class NamespaceFabric {
        AmendNamespace(NamespaceAmender)
    }

    Fabric <|-- NamespaceFabric : derives from

    class TypeFabric {
        AmendType(TypeAmender)
    }

    Fabric <|-- TypeFabric : derives from


Amenders

classDiagram

    class IAmender {
        Project
    }

    class IDeclarationSelector {
        With()
    }

    IDeclarationSelector <|-- IAmender : derives from

    class IDeclarationSelection {
        AddAspect()
        AddAnnotation()
        RegisterValidator()
        RequireAspect()
    }

    IDeclarationSelection <-- IDeclarationSelector : creates

    class IProjectAmender {

    }

    IAmender <|-- IProjectAmender
    IAmender <|-- INamespaceAmender
    IAmender <|-- ITypeAmender

    class INamespaceAmender  {
        Namespace
    }

    class ITypeAmender  {
        Type
        Advice : IAdviceFactory
    }

    IAdviceFactory <-- ITypeAmender : exposes

Namespace member

Classes

Fabric

Allows adding aspects or analyzing a project, namespace, or type just by adding a type inheriting this class. You cannot inherit this class directly, inherit from ProjectFabric, NamespaceFabric, or TypeFabric instead.

NamespaceFabric

A class that, when inherited by a type in a given namespace, allows that type to analyze and add aspects to that namespace.

ProjectFabric

A class that, when inherited by a type in a project (under any name or namespace), allows that type to analyze and add aspects to that project.

TransitiveProjectFabric

A class that, when inherited 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 class that, when inherited by a nested type in a given type, allows that nested type to analyze and add aspects to the parent type.

Interfaces

IAmender

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.