GeneratorInitializationContext.RegisterForPostInitialization Method

Definition

Register a callback that is invoked after initialization.

public void RegisterForPostInitialization (Action<Microsoft.CodeAnalysis.GeneratorPostInitializationContext> callback);
member this.RegisterForPostInitialization : Action<Microsoft.CodeAnalysis.GeneratorPostInitializationContext> -> unit
Public Sub RegisterForPostInitialization (callback As Action(Of GeneratorPostInitializationContext))

Parameters

callback
Action<GeneratorPostInitializationContext>

An Action<T> that accepts a GeneratorPostInitializationContext that will be invoked after initialization.

Remarks

This method allows a generator to opt-in to an extra phase in the generator lifecycle called PostInitialization. After being initialized any generators that have opted in will have their provided callback invoked with a GeneratorPostInitializationContext instance that can be used to alter the compilation that is provided to subsequent generator phases.

For example a generator may choose to add sources during PostInitialization. These will be added to the compilation before execution and will be visited by a registered ISyntaxReceiver and available for semantic analysis as part of the Compilation

Note that any sources added during PostInitialization will be visible to the later phases of other generators operating on the compilation.

Applies to