我有一个 C# 9.0 源代码生成器,它引用一个类库,该类库包含一个用于标识要处理的类的属性。我现在正在编写单元测试,如下所述:
Compilation inputCompilation = CreateCompilation(@"
using Dependncy;
namespace MyCode
{
[Marker]
public partial class SimpleObject
{
[PropertyMarker(0)]
public int Test{get;set;}
}
}
");
var generator = new MyCodeGen();
// Create the driver that will control the generation, passing in our generator
GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);
// Run the generation pass
// (Note: the generator driver itself is immutable, and all calls return an updated version of the driver that you should use for subsequent calls) …Run Code Online (Sandbox Code Playgroud)