with one click
metalama-2026-1
// Complete Metalama documentation for aspect-oriented programming in C#. Use when writing aspects, templates, fabrics, or meta-programming code with Metalama.
// Complete Metalama documentation for aspect-oriented programming in C#. Use when writing aspects, templates, fabrics, or meta-programming code with Metalama.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | metalama-2026.1 |
| description | Complete Metalama documentation for aspect-oriented programming in C#. Use when writing aspects, templates, fabrics, or meta-programming code with Metalama. |
This skill contains the complete Metalama documentation including conceptual guides, API reference, and sample code.
This skill pertains to Metalama 2026.1.
| Directory | Contents |
|---|---|
content/conceptual/ | Conceptual documentation (aspects, templates, fabrics, validation, etc.) |
content/patterns/ | Pattern libraries (contracts, caching, observability, memoization, DI) |
content/api/ | API documentation overview pages |
code/ | Sample code (.cs = source, .t.cs = transformed output, .Aspect.cs = aspect implementation) |
api/ | API reference YML files from DocFx |
-B3 to search index.yml for keywords (each entry has: name, path, summary, keywords - so -B3 captures the path):
grep -i -B3 "caching" index.yml
grep -i -B3 "BuildAspect" index.yml
content/ directory structure.api/.manifest to find API YML files by type or member name:
grep -i "OverrideMethodAspect" api/.manifest
| Topic | File | Description |
|---|---|---|
| Getting Started | content/conceptual/using/using-metalama.md | How to use Metalama in your projects |
| Creating Aspects | content/conceptual/aspects/aspects.md | Overview of aspect creation |
| Overriding Methods | content/conceptual/aspects/simple-aspects/overriding-methods.md | Basic method interception |
| Templates | content/conceptual/aspects/templates/templates.md | T# template syntax and patterns |
| Fabrics | content/conceptual/using/fabrics/fabrics.md | Bulk aspect application |
| Contracts | content/patterns/contracts/contract-patterns.md | Parameter/property validation |
| Caching | content/patterns/caching/caching.md | Method result caching |
| Observability | content/patterns/observability/observability.md | INotifyPropertyChanged implementation |
| Debugging Aspects | content/conceptual/aspects/testing/debugging-aspects.md | Debug compile-time code, breakpoints, meta.DebugBreak() |
| Debugging User Code | content/conceptual/using/debugging-aspect-oriented-code.md | Debug run-time transformed code, LamaDebug configuration |
| Base Class | Target | Key Override | Use When |
|---|---|---|---|
OverrideMethodAspect | Methods | OverrideMethod() | Wrap/intercept methods |
OverrideFieldOrPropertyAspect | Fields/Properties | OverrideProperty | Wrap property access |
ContractAspect | Parameters/Fields/Properties | Validate(dynamic? value) | Validate values |
TypeAspect | Types | BuildAspect() | Introduce members, implement interfaces |
MethodAspect | Methods | BuildAspect() | Programmatic method transformation |
TypeFabric | Single type | AmendType() | Bulk changes to one type |
ProjectFabric | Project | AmendProject() | Apply aspects across project |
[!IMPORTANT] T# templates look like C# but have different semantics. Code that works in normal C# may not work identically in a template. Always read the full template documentation at
content/conceptual/aspects/templates/before writing template code.
public override dynamic? OverrideMethod()
{
// Pre-logic
try
{
return meta.Proceed(); // Calls original method
}
finally
{
// Post-logic (always runs)
}
}
dynamic? handles any return type (void returns null)meta.Proceed() auto-transforms to await for async targetsmeta.Target.* to access compile-time information about the target declarationmeta.DebugBreak() (not Debugger.Break())Debugging compile-time code (aspects, fabrics, templates):
Debugger.Break() in BuildAspect/fabrics, or meta.DebugBreak() in templatesdotnet build -p:MetalamaDebugCompiler=True -p:MetalamaConcurrentBuildEnabled=Falseobj/.../metalama/)Debugging run-time code (transformed output):
LamaDebug build configuration in Visual StudioF11 to step into code, or add Debugger.Break()obj/<Config>/<TFM>/metalama/| Mistake | Correct Approach |
|---|---|
Using Debugger.Break() in templates | Use meta.DebugBreak() in templates; Debugger.Break() only works in BuildAspect and fabrics |
| Setting breakpoints in source files | Breakpoints don't work in Metalama-transformed projects; use Debugger.Break()/meta.DebugBreak() then set breakpoints in transformed code |
Using nameof() for introduced members | Use string literals; nameof() resolves at aspect compile-time, not target compile-time |
| Filtering all types by namespace in fabrics | Use GlobalNamespace.GetDescendant("Ns") or a NamespaceFabric instead of SelectTypes().Where(t => t.Namespace...) |
Forgetting partial on target classes | Classes receiving introduced members need the partial modifier |
Name.cs - Target code receiving the aspectName.Aspect.cs - Aspect implementationName.t.cs - Transformed output (what the compiler generates)Name.Dependency.cs - Referenced project code for multi-project examplesThe documentation uses custom [!metalama-*] directives to include code samples. These are processed at build time to generate HTML, but in the skill files you see the raw directives.
When you see a directive in a Markdown file, extract the file path and read the referenced file directly.
| Directive | Purpose | Example |
|---|---|---|
[!metalama-file PATH] | Shows a single source file | [!metalama-file ~/code/Project/File.cs] |
[!metalama-test PATH] | Shows test with input/output | [!metalama-test ~/code/Project/Test.cs] |
[!metalama-compare PATH] | Shows side-by-side diff | [!metalama-compare ~/code/Project/File.cs] |
[!metalama-vimeo ID] | Embeds Vimeo video | [!metalama-vimeo 842168905] |
~/ resolves to the SKILLS.md directory~/code/Metalama.Documentation.SampleCode.AspectFramework/GettingStarted/GettingStarted.cs
→ Read code/Metalama.Documentation.SampleCode.AspectFramework/GettingStarted/GettingStarted.csWhen you encounter a directive like [!metalama-file ~/code/Project/File.cs]:
code/Project/File.csFile.Aspect.cs - Aspect implementationFile.t.cs - Transformed outputFile.Fabric.cs - Fabric codeMarkers: If you see marker="NAME", look for code between // [<snippet NAME>] and // [<endsnippet NAME>] in the file.
The api/ directory contains DocFx-generated YML files for all public APIs.
Use api/.manifest - a JSON index mapping all UIDs (types, members, overloads) to their YML files.
Search the manifest for the type or member name:
"Metalama.Framework.Aspects.OverrideMethodAspect": "Metalama.Framework.Aspects.OverrideMethodAspect.yml"
"Metalama.Framework.Aspects.OverrideMethodAspect.OverrideMethod": "Metalama.Framework.Aspects.OverrideMethodAspect.yml"
"Metalama.Framework.Code.IMethod": "Metalama.Framework.Code.IMethod.yml"
Read the corresponding YML file to get full documentation.
Naming conventions:
Namespace.TypeName.ymlIAspectBuilder<T> → Metalama.Framework.Aspects.IAspectBuilder-1.ymlEach type's YML file contains all members of that type in a single file:
items:
- uid: Namespace.TypeName # Type definition
commentId: T:Namespace.TypeName
type: Class|Interface|Enum|...
summary: Type description
remarks: Detailed explanation
syntax:
content: public class TypeName : BaseClass
children: # List of member UIDs
- Namespace.TypeName.Method1
- Namespace.TypeName.Property1
- uid: Namespace.TypeName.Method1 # Member definition
commentId: M:Namespace.TypeName.Method1
type: Method|Property|Field|...
summary: Member description
syntax:
content: public void Method1()
parameters: [...] # For methods
return: { type: ..., description: ... }
| Namespace | Purpose |
|---|---|
Metalama.Framework.Aspects | Aspect base classes, attributes, meta API |
Metalama.Framework.Code | Code model interfaces (IMethod, IType, IParameter, etc.) |
Metalama.Framework.Advising | Advice APIs for introducing members, implementing interfaces |
Metalama.Framework.Eligibility | Eligibility builders for aspect targeting |
Metalama.Framework.Diagnostics | Reporting warnings and errors |
Metalama.Framework.Fabrics | Fabric base classes |
Metalama.Patterns.Contracts | Contract validation aspects |
Metalama.Patterns.Caching | Caching aspects and configuration |
Metalama.Patterns.Observability | INotifyPropertyChanged implementation |
Metalama.Extensions.DependencyInjection | Dependency injection |
Metalama.Extensions.Architecture | Architecture enforcement/validation |
When referencing documentation articles, provide links to the live documentation at https://doc.metalama.net.
URL format: https://doc.metalama.net/<path> where <path> is derived from the file path under content/:
content/ prefix.md suffixpath/leaf/leaf.md), use just path/leafExamples:
| File Path | URL |
|---|---|
content/conceptual/aspects/aspects.md | https://doc.metalama.net/conceptual/aspects |
content/conceptual/aspects/templates/templates.md | https://doc.metalama.net/conceptual/aspects/templates |
content/patterns/caching/caching.md | https://doc.metalama.net/patterns/caching |
content/conceptual/aspects/simple-aspects/overriding-methods.md | https://doc.metalama.net/conceptual/aspects/simple-aspects/overriding-methods |