Open sandboxFocus

Method RequireAspect

RequireAspect<TAspect>(IQuery<IDeclaration>)

Requires an instance of a specified aspect type to be present on a specified declaration. If the aspect is not present, this method adds a new instance of the aspect using the default aspect constructor.

Declaration
public static void RequireAspect<TAspect>(this IQuery<IDeclaration> query) where TAspect : class, IAspect, new()
Parameters
Type Name Description
IQuery<IDeclaration> query
Type Parameters
Name Description
TAspect

Type of the aspect. The type must have a default constructor and be ordered after the aspect type calling this method.

Remarks

This method differs from AddAspect<TAspect>(IQuery<IDeclaration>) in that it does not create a secondary aspect instance if the aspect already exists on the target. Instead, it simply registers the current aspect as a predecessor of the existing aspect.

Calling this method causes the current aspect to be present in the Predecessors list even if the required aspect was already present on the target declaration. This allows the required aspect to access the requiring aspect's state if needed.

See Also