Open sandboxFocus

Class TypeFabric

A compile-time entry point implemented as a nested type that executes within the compiler and IDE to add aspects and implement transformations for its containing type.

Inheritance
TypeFabric
Namespace: Metalama.Framework.Fabrics
Assembly: Metalama.Framework.dll
Syntax
public abstract class TypeFabric : Fabric, ICompileTimeSerializable, ITemplateProvider
Remarks

Type fabrics are unique nested classes that execute at compile time and design time. Unlike aspects, fabrics do not need to be applied to any declaration or called from anywhere: their primary method (AmendType(ITypeAmender)) is invoked automatically simply because the nested class exists in the parent type.

A TypeFabric allows you to advise the current type programmatically, functioning as a type-level aspect added to the target type. This is useful when you want to apply transformations to different members of a type without creating a reusable aspect.

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

Type fabrics are always executed first, before any aspect. As a result, they can only add advice to members defined in the source code. If you need to add advice to members introduced by an aspect, use a helper aspect and order it after the aspects that provide the members you wish to advise.

Constructors

Name Description
TypeFabric()

Methods

Name Description
AmendType(ITypeAmender)

Implement this method to programmatically advise the containing type, add aspects to its members, configure options, validate architecture, and report or suppress diagnostics. This method is invoked automatically at compile time and design time. You can also add declarative advice such as member introductions to the type fabric class itself.

Extension Methods

See Also