Код: Выделить всё
public class XmlCommentIncrementalGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var members = context.CompilationProvider
.Select((compilation, _) => {
var names = compilation.GlobalNamespace.GetNamespaceMembers()
.Where(x => x.Name.Contains("SourceGenTest") || x.Name.Contains("SomeLib")) //gets the namespaces
.SelectMany(x=> x.GetMembers()) //gets classes
.Select(x => $"{x.Name} DSR:{x.DeclaringSyntaxReferences.FirstOrDefault()}");
return names.ToImmutableArray();
});
context.RegisterSourceOutput(members, (ctx, array) => {
string output = "//" + string.Join("\n//", array);
ctx.AddSource("Output.g.cs", SourceText.From(output, Encoding.UTF8));
}
);
}
}
- sourcegentest - базовый проект, приложение консоли, имеет ссылку на исходный диаметр и somelib
- source> - сильное> - сильное> - сильное Lib, нет ссылок. На ссылке на ссылке SourceGentest
//ClassInBaseProj DSR:Microsoft.CodeAnalysis.CSharp.SimpleSyntaxReference
//ClassInLib DSR:
< /code>
Как вы можете видеть класс, который находится в базовом проекте (
Код: Выделить всё
ClassInBaseProj
Полный исходный код на GitHub.
Подробнее здесь: https://stackoverflow.com/questions/792 ... ctreferenc