Я использую IIncrementalGenerator и context.SyntaxProvider.ForAttributeWithMetadataName, чтобы получить фактические целевые узлы. Во второй лямбде при выполнении преобразования я пытаюсь получить экземпляр System.Type.
Пример кода:
Код: Выделить всё
public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.SyntaxProvider.ForAttributeWithMetadataName("Name.Of.AttributeAttribute",
(node, ct) => //filter logic
(generatoraAttributeSyntaxContext, CancellationToken ct) =>
{
var nameOfPassedType = generatoraAttributeSyntaxContext.TargetSymbol.GetAttributes()[0].ConstructorArguments[0].Value.ToString()
//Some further code
}
}
Код: Выделить всё
public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.SyntaxProvider.ForAttributeWithMetadataName("Name.Of.AttributeAttribute",
(node, ct) => //filter logic
(generatoraAttributeSyntaxContext, CancellationToken ct) =>
{
System.Type passedType = generatoraAttributeSyntaxContext. //Some further logic to actually acquire the type
//Some further code
}
}
Подробнее здесь: https://stackoverflow.com/questions/778 ... ystem-type