| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | |
| | | 3 | | using NexusLabs.Needlr.Generators; |
| | | 4 | | |
| | | 5 | | namespace MultiProjectApp.Features.CrossGenSimulation; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Represents a type that was emitted by a second source generator. |
| | | 9 | | /// TypeRegistryGenerator cannot see this type because NeedlrAutoGenerate is disabled for this |
| | | 10 | | /// assembly, simulating what happens when another generator produces types at compile time — |
| | | 11 | | /// those types are invisible to TypeRegistryGenerator because it operates on the original |
| | | 12 | | /// compilation snapshot, before any other generator has emitted code. |
| | | 13 | | /// </summary> |
| | | 14 | | public interface ICrossGeneratedPlugin { } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// A plugin type that exists only because a hypothetical second generator emitted it. |
| | | 18 | | /// TypeRegistryGenerator has no knowledge of this type. It reaches the Needlr registry |
| | | 19 | | /// exclusively through <see cref="CrossGenSimulationRegistrations"/>. |
| | | 20 | | /// </summary> |
| | | 21 | | public sealed record SimulatedGeneratorPlugin : ICrossGeneratedPlugin { } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Simulates the module initializer that a second source generator would emit to register its |
| | | 25 | | /// types with Needlr at runtime, bypassing the Roslyn generator isolation boundary. |
| | | 26 | | /// </summary> |
| | | 27 | | internal static class CrossGenSimulationRegistrations |
| | | 28 | | { |
| | | 29 | | #pragma warning disable CA2255 |
| | | 30 | | [ModuleInitializer] |
| | | 31 | | internal static void Initialize() |
| | | 32 | | #pragma warning restore CA2255 |
| | 1 | 33 | | { |
| | 1 | 34 | | NeedlrSourceGenBootstrap.RegisterPlugins(static () => |
| | 11 | 35 | | [ |
| | 11 | 36 | | new PluginTypeInfo( |
| | 11 | 37 | | typeof(SimulatedGeneratorPlugin), |
| | 11 | 38 | | [typeof(ICrossGeneratedPlugin)], |
| | 2 | 39 | | static () => new SimulatedGeneratorPlugin(), |
| | 11 | 40 | | []) |
| | 11 | 41 | | ]); |
| | 1 | 42 | | } |
| | | 43 | | } |