Appearance
附录 A:文件路径导航
本页中的所有路径都按“仓库根目录相对路径”书写,不是相对于当前网页文件的路径。
这份附录帮你在主案例里快速定位“生成器写在哪、示例怎么用、测试怎么验证、生成结果去哪里看”。
生成器项目
| 仓库路径 | 用途 |
|---|---|
sample/01-tostring-generator/ToStringGenerator/ToStringGenerator.cs | 主生成器实现,包含 Initialize(...)、TransformClass(...)、GenerateToStringCode(...) |
sample/01-tostring-generator/ToStringGenerator/Models/ClassToGenerate.cs | 类级中间模型,保存类名、命名空间、泛型、嵌套结构等信息 |
sample/01-tostring-generator/ToStringGenerator/Models/PropertyInfo.cs | 属性级中间模型,保存属性名、类型、可空信息等 |
sample/01-tostring-generator/ToStringGenerator/ToStringGenerator.csproj | 生成器工程配置,决定它如何被示例工程以 Analyzer 引用方式接入编译 |
示例项目
| 仓库路径 | 用途 |
|---|---|
sample/01-tostring-generator/ToStringGenerator.Sample/ToStringGenerator.Sample.csproj | 示例工程配置,展示如何引用生成器 |
sample/01-tostring-generator/ToStringGenerator.Sample/Program.cs | 程序入口,用来运行并观察生成的 ToString() 结果 |
sample/01-tostring-generator/ToStringGenerator.Sample/Examples/SimpleClass.cs | 最容易理解的基础示例 |
sample/01-tostring-generator/ToStringGenerator.Sample/Examples/ComplexClass.cs | 展示多个属性和更接近真实业务的类 |
sample/01-tostring-generator/ToStringGenerator.Sample/Examples/GenericClass.cs | 用来验证泛型类生成 |
sample/01-tostring-generator/ToStringGenerator.Sample/Examples/NestedClass.cs | 用来验证嵌套类生成 |
sample/01-tostring-generator/ToStringGenerator.Sample/Examples/EmptyClass.cs | 用来观察边界情况和空属性列表处理 |
测试项目
| 仓库路径 | 用途 |
|---|---|
sample/01-tostring-generator/ToStringGenerator.Tests/TestHelpers.cs | 构造编译环境、运行生成器的测试辅助代码 |
sample/01-tostring-generator/ToStringGenerator.Tests/ToStringGeneratorTests.cs | 针对生成结果做断言的单元测试 |
sample/01-tostring-generator/ToStringGenerator.Tests/ToStringGenerator.Tests.csproj | 测试工程配置 |
生成结果位置
| 仓库路径 | 你通常会在这里看什么 |
|---|---|
sample/01-tostring-generator/ToStringGenerator.Sample/obj/Debug/net8.0/generated | 实际生成的 .g.cs 文件 |
sample/01-tostring-generator/ToStringGenerator.Sample/obj/Debug/net8.0 | 构建中间产物,排查生成器是否参与编译时也常会看这里 |
最推荐的阅读顺序
- 先看
ToStringGenerator.cs - 再看
ClassToGenerate.cs和PropertyInfo.cs - 再看
Program.cs和Examples/*.cs - 最后看
ToStringGeneratorTests.cs
如果你希望先看一页“带源码片段的地图版说明”,先读 源码导读。