跳转至

查看生成的代码

设置方法

通过在 .csproj 文件中添加以下属性,可以查看自动生成的代码。

project.csproj
1
2
3
<PropertyGroup>
  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

查看

生成的文件会显示在 Dependencies>Analyzer>BlazorPathHelper.Generator 下。

generator-source-location

例如,当创建定义 URL 构建器的 WebPaths.cs 时,会生成如下文件:

Auto Generated Code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// <auto-generated />
#nullable enable
#pragma warning disable CS8600
#pragma warning disable CS8601
#pragma warning disable CS8602
#pragma warning disable CS8603
#pragma warning disable CS8604
using System;
using static BlazorPathHelper.BlazorPathHelperUtility;

namespace Example.MudBlazor;

public partial class WebPaths
{
    /// <summary>
    /// 用于路径构建的辅助类
    /// </summary>
    public static partial class Helper
    {
        /// <summary>构建路径字符串: / </summary>
        public static string Home() => "/";
        /// <summary>构建路径字符串: /sample1 </summary>
        public static string Sample1() => "/sample1";
        /// <summary>构建路径字符串: /sample1/child1 </summary>
        public static string Sample1C1() => "/sample1/child1";
        /// <summary>构建路径字符串: /sample1/child2 </summary>
        public static string Sample1C2() => "/sample1/child2";
        /// <summary>构建路径字符串: /sample1/child2/child1 </summary>
        public static string Sample1C2C1() => "/sample1/child2/child1";
        /// <summary>构建路径字符串: /sample2 </summary>
        public static string Sample2() => "/sample2";
        /// <summary>构建路径字符串: /sample2/child1 </summary>
        public static string Sample2C1() => "/sample2/child1";
        /// <summary>构建路径字符串: /sample3 </summary>
        public static string Sample3() => "/sample3";
        /// <summary>构建路径字符串: /sample3/{value:int} </summary>
        public static string Sample3Arg(int Value)
            => string.Format("/sample3/{0}", ToStringForUrl(Value));
    }
}

注意

如果在 Visual Studio 等工具中打开了上述文件,之后即使编辑了 WebPaths.cs,自动生成的文件也可能不会更新。
这种情况下,重启 Visual Studio 等工具可以确保显示正确更新的文件。