Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class TargetTypeTracker : ISyntaxContextReceiver
{
public IImmutableList<TypeDeclarationSyntax> TypesNeedingDtoGening =
ImmutableList.Create<TypeDeclarationSyntax>();
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
{
if (context.Node is TypeDeclarationSyntax cdecl)
if (cdecl.IsDecoratedWithAttribute("generatemappeddto"))
TypesNeedingDtoGening = TypesNeedingDtoGening.Add(
context.Node as TypeDeclarationSyntax);
}
}
internal static class SourceGenExtns
{
internal static bool IsDecoratedWithAttribute(
this TypeDeclarationSyntax cdecl, string attributeName) =>
cdecl.AttributeLists
.SelectMany(x => x.Attributes)
.Any(x => x.Name.ToString().ToLower() == attributeName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment