【问题标题】:Web Api Help Page - all <see cref="MyClass"/> are missingWeb Api 帮助页面 - 缺少所有 <see cref="MyClass"/>
【发布时间】:2014-06-17 16:32:49
【问题描述】:

在我经常使用的源代码文档中:

Get a <see cref="Quote"/> for the specified <see cref="apiOrder"/> object.

这很好地转换为 XmlDocument.xml 中的以下字符串,其中包含已编译的 Web api 帮助页面。

Get a <see cref="T:Supertext.API.POCO.Quote"/> for the specified <see cref="!:apiOrder"/> object.

但由于某些原因,所有这些引用都没有显示。 我们得到的是这样的:

Get a  for the specified  object

我们找到了一些来源,但似乎没有任何效果。帮不上忙:
Web Api Help Page- don't escape html in xml documentation

已过时:
http://thesoftwaredudeblog.wordpress.com/2014/01/04/using-microsoft-asp-net-web-api-2-help-page-part-2/

有什么想法吗?

【问题讨论】:

    标签: asp.net-web-api asp.net-web-api-helppages


    【解决方案1】:

    在 WebAPI 2 帮助中,有一个名为 XmlDocumentationProvider 的类。在这个类中有一个名为GetTagValue 的方法,它处理摘要和返回标签。还有一个名为GetDocumentation的方法(有多个,但它是带有HttpParameterDescriptor参数的方法)处理Param标签。

    我编写了一个函数,该函数使用 RegEx 查找所有“See Cref”并将它们替换为找到的最后一个对象名称。

    正则表达式:

    private static Regex SeeCodeReferenceRegEx = new Regex("<see cref=\\\"\\w:([\\w]+\\.)*(\\w+)\\\" */>", RegexOptions.Compiled);
    

    功能:

    private static string CleanValue(string value)
    {
        value = value.Trim();
        var matches = SeeCodeReferenceRegEx.Matches(value);
        foreach (Match match in matches)
            value = value.Replace(match.Groups[0].Value, match.Groups[2].Value);
        return value;
    }
    

    GetTagValue 中,替换:

    return node.Value.Trim();
    

    与:

    return CleanValue(node.InnerXml);
    

    GetDocumentation 中替换:

    return parameterNode.Value.Trim();
    

    与:

    return CleanValue(parameterNode.InnerXml);
    

    【讨论】:

    • 然而,此解决方案并未将引用显示为链接。相反,它显示为纯文本,这违背了在 XML 文档中添加引用的全部目的。但是是的,至少是一个文本,而不是忽略整个 C ref 标签。
    猜你喜欢
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 2013-07-08
    相关资源
    最近更新 更多