Open sandboxFocus

Interface IQuery<TDeclaration>

Represents a LINQ-like query over a set of code declarations. Provides methods to filter, project, and transform the declaration set, and to apply aspects, validators, configuration, and diagnostics to the selected declarations.

Namespace: Metalama.Framework.Fabrics
Assembly: Metalama.Framework.dll
Syntax
public interface IQuery<out TDeclaration> : IQuery where TDeclaration : class, IDeclaration
Type Parameters
Name Description
TDeclaration

The type of declarations in the current query result set (e.g., INamedType, IMethod, IProperty).

Remarks

This interface provides a fluent API for querying declarations within fabrics. You can chain methods like Where(Func<TDeclaration, bool>), Select<TMember>(Func<TDeclaration, TMember>), SelectMany<TMember>(Func<TDeclaration, IEnumerable<TMember>>), and SelectTypes(bool) to build complex queries. The resulting query can then be used with extension methods from QueryExtensions to add aspects or configure options for the selected declarations.

Query methods are executed concurrently for better performance, so it's preferable to use the query methods provided by this interface rather than using standard LINQ methods inside selector delegates.

Extension methods for this interface are provided by:

  • AspectQueryExtensions - for adding aspects to selected declarations
  • OptionQueryExtensions - for configuring options on selected declarations
  • DiagnosticsQueryExtensions - for reporting diagnostics and suppressions
  • QueryExtensions - for additional querying capabilities
  • Metalama.Extensions.Architecture.Predicates.PredicateExtensions - for architecture validation predicates
  • Metalama.Extensions.Validation.ValidationQueryExtensions - for validation rules
  • Metalama.Extensions.Validation.ReferenceValidationQueryExtensions - for reference validation
  • Metalama.Extensions.CodeFixes.CodeFixQueryExtensions - for code fix suggestions

Methods

Name Description
OfType<TOut>()

Selects all declarations of a given type.

SelectMany<TMember>(Func<TDeclaration, IEnumerable<TMember>>)

Projects each declaration of the current set to an IEnumerable<T> (typically a list of child declarations) and flattens the resulting sequences into one set.

SelectTypes(bool)

Selects all types enclosed in declarations of the current set.

SelectTypesDerivedFrom(INamedType, DerivedTypesOptions)

Selects all types, among those enclosed in declarations of the current set, that derive from or implement a given INamedType.

SelectTypesDerivedFrom(Type, DerivedTypesOptions)

Selects all types, among those enclosed in declarations of the current set, that derive from or implement a given Type.

Select<TMember>(Func<TDeclaration, TMember>)

Projects each declaration of the current set into a new declaration.

Tag<TTag>(Func<TDeclaration, TTag>)
ToCollection(ICompilation?)

Evaluates the current query into a collection. This method should only be used for debugging or testing purposes.

Where(Func<TDeclaration, bool>)

Filters the set of declarations based on a predicate.

WithTag<TTag>(Func<TDeclaration, TTag>)

Projects the declarations in the current set by adding a tag for each declaration, and returns a ITaggedQuery<TDeclaration, TTag>. Methods of this interface have overloads that accept this tag.

Extension Methods

See Also