Base class for implementing custom metrics that analyze Roslyn syntax trees. Derive from this class when your metric needs to examine the actual code structure (statements, expressions, etc.).
Inheritance
SyntaxMetricProvider<T>
Namespace: Metalama.Framework.Engine.Metrics
Assembly: Metalama.Framework.Sdk.dll
Syntax
public abstract class SyntaxMetricProvider<T> : MetricProvider<T>, IMetricProvider<T>, IProjectService, IService where T : struct, IMetricType Parameters
| Name | Description |
|---|---|
| T | The metric type, which must be a struct implementing IMetric. |
Remarks
SyntaxMetricProvider<T> simplifies syntax-based metric implementation by:
- Automatically locating syntax nodes from declarations using DeclaringSyntaxReferences.
- Providing a SyntaxMetricProvider<T>.BaseVisitor class that handles recursive aggregation by default.
- Handling partial declarations by visiting and aggregating each part.
To create a syntax-based metric:
- Create a metric struct implementing IMetric<T>.
- Create a nested visitor class deriving from SyntaxMetricProvider<T>.BaseVisitor and override Visit(SyntaxNode) methods.
- Create a provider class deriving from SyntaxMetricProvider<T>, passing the visitor to the constructor.
- Override Aggregate(ref T, in T) to combine values.
- Annotate the provider class with MetalamaPlugInAttribute.
Constructors
| Name | Description |
|---|---|
| SyntaxMetricProvider(BaseVisitor) |
Methods
| Name | Description |
|---|---|
| ComputeMetricForMember(IMember) | Computes the metric for a member. |
| ComputeMetricForType(INamedType) | Computes the metric for a whole type. |