コード例 #1
0
 public static SyntaxContextReceiverCreator Create(SyntaxReceiverCreator creator) => () =>
 {
     var rx = creator();
     if (rx is object)
     {
         return(new SyntaxContextReceiverAdaptor(rx));
     }
     // in the case that the creator function returns null, we'll also return a null adaptor
     return(null);
 };
コード例 #2
0
ファイル: GeneratorContexts.cs プロジェクト: belav/roslyn
 /// <summary>
 /// Register a <see cref="SyntaxReceiverCreator"/> for this generator, which can be used to create an instance of an <see cref="ISyntaxReceiver"/>.
 /// </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="ISyntaxReceiver"/>. This receiver will have its <see cref="ISyntaxReceiver.OnVisitSyntaxNode(SyntaxNode)"/>
 /// 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="ISyntaxReceiver"/> instance that was
 /// created by accessing the <see cref="GeneratorExecutionContext.SyntaxReceiver"/> property. Any information that was collected by the receiver can be
 /// used to generate the final output.
 ///
 /// A new instance of <see cref="ISyntaxReceiver"/> is created per-generation, meaning there is no need to manage the lifetime of the
 /// receiver or its contents.
 /// </remarks>
 /// <param name="receiverCreator">A <see cref="SyntaxReceiverCreator"/> that can be invoked to create an instance of <see cref="ISyntaxReceiver"/></param>
 public void RegisterForSyntaxNotifications(SyntaxReceiverCreator receiverCreator)
 {
     CheckIsEmpty(
         InfoBuilder.SyntaxContextReceiverCreator,
         $"{nameof(SyntaxReceiverCreator)} / {nameof(SyntaxContextReceiverCreator)}"
         );
     InfoBuilder.SyntaxContextReceiverCreator = SyntaxContextReceiverAdaptor.Create(
         receiverCreator
         );
 }
コード例 #3
0
 public void RegisterForSyntaxNotifications(SyntaxReceiverCreator receiverCreator)
 {
     CheckIsEmpty(InfoBuilder.SyntaxReceiverCreator);
     InfoBuilder.SyntaxReceiverCreator = receiverCreator;
 }