Exemplo n.º 1
0
 /// <summary>
 /// Register a <see cref="SyntaxContextReceiverCreator"/> for this generator, which can be used to create an instance of an <see cref="ISyntaxContextReceiver"/>.
 /// </summary>
 /// <remarks>
 /// This method allows generators to be 'syntax aware'. Before each generation the <paramref name="receiverCreator"/> will be invoked to create
 /// an instance of <see cref="ISyntaxContextReceiver"/>. This receiver will have its <see cref="ISyntaxContextReceiver.OnVisitSyntaxNode(GeneratorSyntaxContext)"/>
 /// invoked for each syntax node in the compilation, allowing the receiver to build up information about the compilation before generation occurs.
 ///
 /// During <see cref="ISourceGenerator.Execute(GeneratorExecutionContext)"/> the generator can obtain the <see cref="ISyntaxContextReceiver"/> instance that was
 /// created by accessing the <see cref="GeneratorExecutionContext.SyntaxContextReceiver"/> property. Any information that was collected by the receiver can be
 /// used to generate the final output.
 ///
 /// A new instance of <see cref="ISyntaxContextReceiver"/> is created prior to every call to <see cref="ISourceGenerator.Execute(GeneratorExecutionContext)"/>,
 /// meaning there is no need to manage the lifetime of the receiver or its contents.
 /// </remarks>
 /// <param name="receiverCreator">A <see cref="SyntaxContextReceiverCreator"/> that can be invoked to create an instance of <see cref="ISyntaxContextReceiver"/></param>
 public void RegisterForSyntaxNotifications(SyntaxContextReceiverCreator receiverCreator)
 {
     CheckIsEmpty(
         InfoBuilder.SyntaxContextReceiverCreator,
         $"{nameof(SyntaxReceiverCreator)} / {nameof(SyntaxContextReceiverCreator)}"
         );
     InfoBuilder.SyntaxContextReceiverCreator = receiverCreator;
 }
Exemplo n.º 2
0
 public SyntaxReceiverStrategy(
     SyntaxContextReceiverCreator receiverCreator,
     Action <IIncrementalGeneratorOutputNode> registerOutput,
     ISyntaxHelper syntaxHelper)
 {
     _receiverCreator = receiverCreator;
     _registerOutput  = registerOutput;
     _syntaxHelper    = syntaxHelper;
 }
Exemplo n.º 3
0
 public SyntaxReceiverInputNode(SyntaxContextReceiverCreator receiverCreator, Action <IIncrementalGeneratorOutputNode> registerOutput)
 {
     _receiverCreator = receiverCreator;
     _registerOutput  = registerOutput;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a syntax receiver input node. Only used for back compat in <see cref="SourceGeneratorAdaptor"/>
        /// </summary>
        internal IncrementalValueProvider <ISyntaxContextReceiver?> CreateSyntaxReceiverProvider(SyntaxContextReceiverCreator creator)
        {
            var node = new SyntaxInputNode <ISyntaxContextReceiver?>(
                new SyntaxReceiverStrategy <ISyntaxContextReceiver?>(creator, _registerOutput, _syntaxHelper), RegisterOutputAndDeferredInput);

            _inputNodes.Add(node);
            return(new IncrementalValueProvider <ISyntaxContextReceiver?>(node));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a syntax receiver input node. Only used for back compat in <see cref="SourceGeneratorAdaptor"/>
        /// </summary>
        internal IncrementalValueProvider <ISyntaxContextReceiver?> CreateSyntaxReceiverProvider(SyntaxContextReceiverCreator creator)
        {
            var node = new SyntaxReceiverInputNode(creator, _registerOutput);

            _inputNodes.Add(node);
            return(new IncrementalValueProvider <ISyntaxContextReceiver?>(node));
        }