I want to generate a static class that should have a method depending on other classes in specific reference assembly.
a simplified example:
// 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()
}
I want to find the Entity
classes in the Core
project and generate a class in the Persistence
project,
The problem is my Core
project is not accessible and it is already compiled before Persistence
. should I use reflection or manually read the Core Entities ? or is there a better way to access SyntaxTree in the Core
project?