Base class for implementing custom metric providers. Derive from this class to create metrics that can measure code characteristics like complexity, coupling, or custom patterns.
Namespace: Metalama.Framework.Engine.Metrics
Assembly: Metalama.Framework.Sdk.dll
Syntax
public abstract class 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
To create a custom metric:
- Create a metric struct implementing IMetric<T> for each declaration type it supports.
- Create a metric provider class deriving from MetricProvider<T> (or SyntaxMetricProvider<T> for syntax-based metrics).
- Annotate the provider class with MetalamaPlugInAttribute.
Override the following methods:
- ComputeMetricForType(INamedType): Compute the metric for a type.
- ComputeMetricForMember(IMember): Compute the metric for a member.
- Aggregate(ref T, in T): Combine metric values when aggregating across members or types.
For syntax-based metrics that analyze syntax trees, use SyntaxMetricProvider<T> instead.
Constructors
| Name | Description |
|---|---|
| MetricProvider() |
Methods
| Name | Description |
|---|---|
| Aggregate(ref T, in T) | Aggregates a new value into an aggregate value. |
| ComputeMetricForMember(IMember) | Computes the metric for a member. |
| ComputeMetricForType(INamedType) | Computes the metric for a whole type. |
| GetMetric(IMeasurable) | Gets the metric for a measurable code element. |