Sdílet prostřednictvím


GeneratorInitializationContext.RegisterForSyntaxNotifications Method

Definition

Overloads

RegisterForSyntaxNotifications(SyntaxContextReceiverCreator)

Register a SyntaxContextReceiverCreator for this generator, which can be used to create an instance of an ISyntaxContextReceiver.

RegisterForSyntaxNotifications(SyntaxReceiverCreator)

Register a SyntaxReceiverCreator for this generator, which can be used to create an instance of an ISyntaxReceiver.

RegisterForSyntaxNotifications(SyntaxContextReceiverCreator)

Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs

Register a SyntaxContextReceiverCreator for this generator, which can be used to create an instance of an ISyntaxContextReceiver.

public void RegisterForSyntaxNotifications (Microsoft.CodeAnalysis.SyntaxContextReceiverCreator receiverCreator);
member this.RegisterForSyntaxNotifications : Microsoft.CodeAnalysis.SyntaxContextReceiverCreator -> unit
Public Sub RegisterForSyntaxNotifications (receiverCreator As SyntaxContextReceiverCreator)

Parameters

receiverCreator
SyntaxContextReceiverCreator

A SyntaxContextReceiverCreator that can be invoked to create an instance of ISyntaxContextReceiver

Remarks

This method allows generators to be 'syntax aware'. Before each generation the receiverCreator will be invoked to create an instance of ISyntaxContextReceiver. This receiver will have its OnVisitSyntaxNode(GeneratorSyntaxContext) invoked for each syntax node in the compilation, allowing the receiver to build up information about the compilation before generation occurs.

During Execute(GeneratorExecutionContext) the generator can obtain the ISyntaxContextReceiver instance that was created by accessing the SyntaxContextReceiver property. Any information that was collected by the receiver can be used to generate the final output.

A new instance of ISyntaxContextReceiver is created prior to every call to Execute(GeneratorExecutionContext), meaning there is no need to manage the lifetime of the receiver or its contents.

Applies to

RegisterForSyntaxNotifications(SyntaxReceiverCreator)

Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs
Source:
GeneratorContexts.cs

Register a SyntaxReceiverCreator for this generator, which can be used to create an instance of an ISyntaxReceiver.

public void RegisterForSyntaxNotifications (Microsoft.CodeAnalysis.SyntaxReceiverCreator receiverCreator);
member this.RegisterForSyntaxNotifications : Microsoft.CodeAnalysis.SyntaxReceiverCreator -> unit
Public Sub RegisterForSyntaxNotifications (receiverCreator As SyntaxReceiverCreator)

Parameters

receiverCreator
SyntaxReceiverCreator

A SyntaxReceiverCreator that can be invoked to create an instance of ISyntaxReceiver

Remarks

This method allows generators to be 'syntax aware'. Before each generation the receiverCreator will be invoked to create an instance of ISyntaxReceiver. This receiver will have its OnVisitSyntaxNode(SyntaxNode) invoked for each syntax node in the compilation, allowing the receiver to build up information about the compilation before generation occurs.

During Execute(GeneratorExecutionContext) the generator can obtain the ISyntaxReceiver instance that was created by accessing the SyntaxReceiver property. Any information that was collected by the receiver can be used to generate the final output.

A new instance of ISyntaxReceiver is created per-generation, meaning there is no need to manage the lifetime of the receiver or its contents.

Applies to