Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save usausa/4fed21613f802bfb9d50bb6fccefeb60 to your computer and use it in GitHub Desktop.
Save usausa/4fed21613f802bfb9d50bb6fccefeb60 to your computer and use it in GitHub Desktop.
public static class IncrementalGeneratorInitializationContextExtensions
{
public static IncrementalValuesProvider<T> ForAttributeWithMetadataNameWithOptions<T>(
this IncrementalGeneratorInitializationContext context,
string fullyQualifiedMetadataName,
Func<SyntaxNode, CancellationToken, bool> predicate,
Func<GeneratorAttributeSyntaxContext, AnalyzerConfigOptions, CancellationToken, T> transform)
{
var syntaxContext = context.SyntaxProvider.ForAttributeWithMetadataName(
fullyQualifiedMetadataName,
predicate,
static (context, _) => context);
var configOptions = context.AnalyzerConfigOptionsProvider.Select(static (provider, _) => provider.GlobalOptions);
return syntaxContext.Combine(configOptions).Select((input, token) => transform(input.Left, input.Right, token));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment