Joh*_*ith 9 .net c# sandcastle chm
我试图在我使用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>
Run Code Online (Sandbox Code Playgroud)
这非常混乱,我宁愿在我的.cs文件中没有这个代码.有没有办法将此示例代码放在单独的.cs文件中,并以某种方式在注释中引用它?所以相反,我会有这样的事情:
/// <summary>
/// Lorem ipsum.
/// </summary>
/// <reference src="mycode.cs">
/// </example>
Run Code Online (Sandbox Code Playgroud)
hel*_*ich 11
当然.假设您创建一个外部代码文件Example.cs.在该文件中,您将放置示例,并以命名方式包围region.
#region example1
Console.WriteLine("Hello, World!");
#endregion
Run Code Online (Sandbox Code Playgroud)
在为您创建示例的元素的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
{
// ...
Run Code Online (Sandbox Code Playgroud)
C#不需要指定语言,因为这是默认语言,如果您没有指定区域,它将包含示例文件中的所有代码.
另请注意,源文件路径是相对于SHFB项目文件的,不一定是Visual Studio项目文件.如果配置代码块组件(在SHFB - >项目属性 - >组件中),则可以指定不同的基本路径.
| 归档时间: |
|
| 查看次数: |
1604 次 |
| 最近记录: |