gpt4 book ai didi

c# - 在 SandcaSTLes 的单独文件中包含代码示例

转载 作者:太空狗 更新时间:2023-10-29 17:46:21 25 4
gpt4 key购买 nike

我正在尝试在使用 SandcaSTLes 生成的 CHM 文件中包含代码示例。这是我目前所拥有的:

/// <summary>
/// Lorem ipsum.
/// </summary>
/// <example>
/// <code>
/// public int Test
/// {
/// private int test { get; set }
/// private int test2 { get; set; }
/// public int findE()
/// {
/// if(test == test2){
/// return Console.WriteLine("Variables are Equal")
/// }
/// else{
/// return Console.WriteLine("Variables are not equal")
/// }
/// }
/// }
/// </code>
/// </example>

这太乱了,我不想在我的 .cs 文件中包含这段代码。有没有办法将此示例代码放在单独的 .cs 文件中,并以某种方式在评论中引用它?所以相反,我会有这样的东西:

/// <summary>
/// Lorem ipsum.
/// </summary>
/// <reference src="mycode.cs">
/// </example>

最佳答案

当然。假设您创建了一个外部代码文件 Example.cs。在那个文件中,你放置了你的例子,周围是一个命名的 region

#region example1
Console.WriteLine("Hello, World!");
#endregion

在您为其创建示例的元素的 XML 注释中,您指定外部代码示例的来源:

/// <summary>blah blah my class</summary>
/// <example><code source="Example.cs" region="example1" lang="C#"
/// title="Some Title to Display" /></example>
public class Hurr
{
// ...

C# 不需要指定语言,因为这是默认语言,如果您不指定区域,它将包含示例文件中的所有代码。

另请注意,源文件路径是相对于您的 SHFB 项目文件的,不一定是 Visual Studio 项目文件。如果您配置代码块组件(在 SHFB -> 项目属性 -> 组件中),您可以指定不同的基本路径。

关于c# - 在 SandcaSTLes 的单独文件中包含代码示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26021136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com