Open sandboxFocus

Class SyntaxMetricProvider<T>

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.).

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, IMetric
Type Parameters
Name Description
T

The metric type, which must be a struct implementing IMetric.

Remarks

SyntaxMetricProvider<T> simplifies syntax-based metric implementation by:

To create a syntax-based metric:

  1. Create a metric struct implementing IMetric<T>.
  2. Create a nested visitor class deriving from SyntaxMetricProvider<T>.BaseVisitor and override Visit(SyntaxNode) methods.
  3. Create a provider class deriving from SyntaxMetricProvider<T>, passing the visitor to the constructor.
  4. Override Aggregate(ref T, in T) to combine values.
  5. 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.

Extension Methods

See Also