C#XML文档网站链接

joh*_*ohn 124 c# xml hyperlink

是否可以在XML文档中包含指向网站的链接?例如,我的方法总结为

///<Summary>
/// This is a math function I found HERE.
///</Summary>
public void SomeMathThing(Double[] doubleArray)
{
   ...
}
Run Code Online (Sandbox Code Playgroud)

当我打字的时候

SomeMathThing(
Run Code Online (Sandbox Code Playgroud)

我希望IntelliSense显示摘要,并选择单击"此处"链接到外部网站.这可能吗?怎么做?

diz*_*ave 124

尝试:

///<Summary>
/// This is a math function I found <see href="http://stackoverflow.com">HERE</see>
///</Summary>
Run Code Online (Sandbox Code Playgroud)

  • 这适用于 VS 16.4.2。不确定添加了什么版本,只是您现在可以单击方法信息窗口中的链接。 (8认同)
  • 没有运气我害怕.它甚至没有显示"HERE". (6认同)
  • 嗯,道歉.我做了一些研究(见[这里](http://social.msdn.microsoft.com/Forums/en-US/devdocs/thread/8af32a12-bebe-447b-9111-dbe5d970810d)和[这里](http ://social.msdn.microsoft.com/Forums/en/csharpide/thread/82d85250-e5ac-48f2-a787-2ca441904c2c)) - 看起来VS IDE不会显示那些超链接,而是一个文档工具例如SandCastle就可以显示它们. (5认同)
  • 在 VS 2019 中运行,确切的版本号是 VS 16.6.4。首先我尝试使用“cref”,但“href”渲染得很好。一个技巧是,当工具提示悬停时,将鼠标指针移到工具提示之外,然后您也可以单击链接导航到 URL。伟大的东西VS!它在 VS Code 中也能工作吗?嗯嗯.. (3认同)
  • 你可以阅读关于 Sandcastle [这里](http://elegantcode.com/2008/04/01/inline-xml-code-documentation-using-sandcastle/) 顺便说一句。“由 Microsoft 创建的 Sandcastle 是一个免费工具,用于从 .NET 程序集及其关联的 XML 注释文件创建 MSDN 样式的文档。它基于命令行,没有 GUI 前端、项目管理功能或自动化构建过程。” 哼! (2认同)
  • 对我来说它不起作用,因为我的链接的网址中有一个&符号。一旦我将其更改为“https://somewhere.com?test1=1&amp;test2=2”,它就起作用了。 (2认同)

MHo*_*ayr 64

炒作有点晚了,但这是我在Visual Studio 2015中发现的.

我的示例如下所示:

    /// <summary>
    ///     Retrieves information about the specified window. 
    ///     The function also retrieves the value at a specified offset into the extra window memory.
    ///     From <see cref="!:https://msdn.microsoft.com/en-us/library/windows/desktop/ms633585(v=vs.85).aspx">this</see> MSDN-Link.
    ///     AHref <a href="http://stackoverflow.com">here</a>.
    ///     see-href <see href="http://stackoverflow.com">here</see>.
    /// </summary>
    /// <param name="hwnd"></param>
    /// <param name="index"></param>
    /// <returns>
    ///     Testlink in return: <a href="http://stackoverflow.com">here</a>
    /// </returns>
    public static IntPtr GetWindowLongPtr(IntPtr hwnd, int index)
    {
        return IntPtr.Size == 4 ? GetWindowLongPtr32(hwnd, index) : GetWindowLongPtr64(hwnd, index);
    }
Run Code Online (Sandbox Code Playgroud)

结果是:

  1. 工具提示:
    • 用!:显示cref-url,但隐藏"this"
    • 隐藏ahref-url但显示文本
    • 隐藏seehref网址和文字 intellisense工具提示的屏幕截图

  1. 对象浏览器:
    • 用!:显示cref-url,但隐藏"this"(不可点击)
    • 隐藏ahref-url但显示文本(不可点击)
    • 隐藏seehref网址和文字(不可点击) ObjectBrowser的屏幕截图

  1. ReSharper(CTRL + SHIFT + F1,Command ReSharper.ReSharper_QuickDoc)
    • 使用!:隐藏cref-url,但显示"this"(不可点击)
    • 现在解释ahref-url(2016年及更新的版本)
    • 隐藏seehref网址和文字(不可点击) Resharper QuickHelp的屏幕截图

结论:正如海纳指出的那样,最好的一个就是

See <a href="link">this link</a> for more information.
Run Code Online (Sandbox Code Playgroud)

更新 正如ThomasHagström指出的那样,Resharper现在支持可点击的a-href网址.相应更新截图.

  • 实际上,使用ReSharper和CTRL + SHIFT + F1,可以点击URL并且HTML链接兼容,所以这确实是最好的选择 (2认同)
  • +1 刚刚确认 JetBrains Rider(JetBrains 的完整 C# IDE,具有许多 Resharper 功能)仅支持“&lt;a href="..."&gt;文本&lt;/a&gt;”,并且如果您尝试`&lt;see href="..."&gt;文本&lt;/see&gt;` (2认同)

Hei*_*ner 21

您可以使用标准HTML语法:

<a href="http://stackoverflow.com">here</a>
Run Code Online (Sandbox Code Playgroud)

该文本将显示在Visual Studio中.

  • 该链接在 VS 2022 中变得可点击。这应该是可接受的答案。 (7认同)
  • 这是最好的方法.因为输出在Visual Studio中仍然有意义(它只显示文本),链接将在Sandcastle等文档工具中使用. (4认同)
  • 在 JetBrains Rider 2021.3 中只有这种方法对我有用 (3认同)

fub*_*aar 18

你可以在cref中包含一个!:前缀,使其在生成的Xml文档中不受影响,以便像Innovasys Document这样的工具!X和Sandcastle将使用它.例如

/// <summary>
/// This is a math function I found <see cref="!:http://stackoverflow.com">HERE</see>
/// </summary>
Run Code Online (Sandbox Code Playgroud)

Visual Studio intellisense不会将其显示为intellisense的链接 - 因为它是工具提示所以不会有太大的意义,因此无论如何都无法点击它.

  • 如果[对象浏览器实际上使`<see />`clickable](http://stackoverflow.com/q/20517119/429091)*和*以某种方式识别网站URI(因为对象浏览器不是工具提示),这是有意义的).只是在说' ;-). (2认同)

Ram*_*yev 11

使用<a>标签。例如,我在我的项目中使用了这个解决方案:

结果:

我的 XML 代码:

/// <summary>
/// This is C# XML Documentation Website Link
/// <a href="/sf/ask/487229851/">See more</a>
/// </summary>
Run Code Online (Sandbox Code Playgroud)

或者使用<see>标签。结果与<a>标签相同。

/// <summary>
/// This is C# XML Documentation Website Link
/// <see href="/sf/ask/487229851/">See more</see>
/// </summary>
Run Code Online (Sandbox Code Playgroud)