小编Aka*_*ade的帖子

如何在单元测试中使用C# 9源代码生成器的引用?

我有一个 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)

c# roslyn c#-9.0 sourcegenerators

5
推荐指数
0
解决办法
707
查看次数

标签 统计

c# ×1

c#-9.0 ×1

roslyn ×1

sourcegenerators ×1