我想生成一个静态类,该类应该有一个方法,具体取决于特定参考程序集中的其他类。
一个简化的例子:
// Generator.csproj
[Generator]
public class MyGenerator : ISourceGenerator
{
public void Initialize(GeneratorInitializationContext context)
{
// Register a factory that can create our custom syntax receiver
context.RegisterForSyntaxNotifications(() => new MySyntaxReceiver());
}
public void Execute(GeneratorExecutionContext context)
{
// var syntaxReceiver = (MySyntaxReceiver)context.SyntaxReceiver;
}
}
private class MySyntaxReceiver : ISyntaxReceiver
{
....
}
// Core.csproj
// namespace Core.Entities
class Entity1 : IAccessControl {}
class Entity2 {}
class Entity3 : IAccessControl {}
// Persistence.csproj => has a reference to Core project and the Generator
// this class should be generated ...
static class GeneratedClass
{
public static void DoSomethingEntity1()
public static void DoSomethingEntity3()
}
我想在项目中找到Entity
类并在Core
项目中生成一个类Persistence
,问题是我的Core
项目无法访问并且之前已经编译过Persistence
。我应该使用反射还是手动读取核心实体?还是有更好的方法来访问项目中的 SyntaxTree Core
?