Open sandboxFocus

Class OptionQueryExtensions

Extension methods for IQuery<TDeclaration> and ITaggedQuery<TDeclaration, TTag> to set hierarchical options.

Inheritance
OptionQueryExtensions
Namespace: Metalama.Framework.Options
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public static class OptionQueryExtensions
Remarks

These extension methods allow fabrics and aspects to configure hierarchical options for declarations selected by queries. This is the primary mechanism for applying options at scale across a project, namespace, or type family.

The SetOptions<TDeclaration, TOptions>(IQuery<TDeclaration>, TOptions) methods are typically called from fabric classes (such as ProjectFabric, NamespaceFabric, or TypeFabric) on the Outbound property to configure aspects throughout the codebase.

Builder Pattern for Better User Experience: For complex option classes, aspect authors can improve the user experience by providing a builder pattern. Create custom extension methods (e.g., ConfigureMyAspect(this IQuery<T> query, Action<MyOptionsBuilder> configure)) that accept a configuration delegate. The extension method creates a builder instance, invokes the delegate to configure it, calls Build() to produce the options object, and finally calls SetOptions<TDeclaration, TOptions>(IQuery<TDeclaration>, TOptions). This allows users to write fluent configuration code without dealing with nullable properties directly. For a complete example, see Metalama.Extensions.DependencyInjection:

Methods

Name Description
SetOptions<TDeclaration, TOptions>(IQuery<TDeclaration>, Func<TDeclaration, TOptions>)

Sets options for the declarations in the current set of declarations by supplying a Func<TResult>.

SetOptions<TDeclaration, TOptions>(IQuery<TDeclaration>, TOptions)

Sets options for the declarations in the current set of declarations by supplying a Func<TResult>.

SetOptions<TDeclaration, TTag, TOptions>(ITaggedQuery<TDeclaration, TTag>, Func<TDeclaration, TTag, TOptions>)

Sets options for the declarations in the current set of declarations by supplying a Func<TResult>.

See Also