关于ASP.NET Web Api的HelpPage文档注释问题

以前我用微软的HelpPage来自动生成的webAPI帮助文档。在使用了一段时间后发现只能显示Controller上面写的注释文档内容。以前总以为是微软这个类库的bug。后来才明白了是由于我的设置不当。

微软的HelpPage类库
controller上的注释
AlarmRecodrdDto文档
我们可以很清楚的看到,返回的`AlarmRecodrdDto`并没有注释文档啊!可是我已经在类库的中写过了该代码的注释的。为毛就没有呢???

其实啊,我们的注释文档是自动生成xml文件,再由HelpPage来读取该xml中的注释信息,最后展示在页面上。那些没有注释的文档是由于我们的代码注释没有生成对应的注释xml文件,所以就没法读取啦!!!

明白问题出在哪里了就可以动手解决问题了!!!

1. 设置指定类库中要生成的注释xml路径

GTCASP.Services.xml
GTCASP.Models.xml
XMLDocument.xml

2. 添加一个可以读取xml文件信息的类

using System;
using System.Linq;
using System.Reflection;
using System.Web.Http.Controllers;
using System.Web.Http.Description;
using GTCASP.Website.Areas.HelpPage.ModelDescriptions; namespace GTCASP.Website.Areas.HelpPage.Models
{
/// <summary>A custom
/// <see cref="IDocumentationProvider"/>
/// that reads the API documentation from a collection of XML documentation files.
/// </summary>
public class MultiXmlDocumentationProvider : IDocumentationProvider, IModelDocumentationProvider
{
/*********
** Properties
*********/
/// <summary>The internal documentation providers for specific files.</summary>
private readonly XmlDocumentationProvider[] Providers; /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="paths">The physical paths to the XML documents.</param>
public MultiXmlDocumentationProvider(params string[] paths)
{
this.Providers = paths.Select(p => new XmlDocumentationProvider(p)).ToArray();
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(MemberInfo subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(Type subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(HttpControllerDescriptor subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(HttpActionDescriptor subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(HttpParameterDescriptor subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetResponseDocumentation(HttpActionDescriptor subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /*********
** Private methods
*********/
/// <summary>Get the first valid result from the collection of XML documentation providers.</summary>
/// <param name="expr">The method to invoke.</param>
private string GetFirstMatch(Func<XmlDocumentationProvider, string> expr)
{
return this.Providers
.Select(expr)
.FirstOrDefault(p => !String.IsNullOrWhiteSpace(p));
}
}
}

请将类添加到如下位置

1488537641166.jpg

3. 修改HelpPageConfig.cs中的代码。

1488537734229.jpg

做完以上设置后,大功告成。妹子,现在我们可以出去玩啦!!!

咦,妹子人呢?

关于ASP.NET Web Api的HelpPage文档注释问题的更多相关文章

  1. 关于Web Api的HelpPage文档注释问题

    之前使用Microsoft.AspNet.WebApi.HelpPage的时候,一直为返回对象的注释发愁,以为这是个BUG. 这个注释的解决办法其实要从其原理理解就明白了. 因为HelpPage是读取 ...

  2. ASP.NET Core 中文文档 第二章 指南 (09) 使用 Swagger 生成 ASP.NET Web API 在线帮助测试文档

    原文:ASP.NET Web API Help Pages using Swagger 作者:Shayne Boyer 翻译:谢炀(kiler) 翻译:许登洋(Seay) 对于开发人员来说,构建一个消 ...

  3. asp.net core web api 生成 swagger 文档

    asp.net core web api 生成 swagger 文档 Intro 在前后端分离的开发模式下,文档就显得比较重要,哪个接口要传哪些参数,如果一两个接口还好,口头上直接沟通好就可以了,如果 ...

  4. Effective Java 第三版——56. 为所有已公开的API元素编写文档注释

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  5. 第四十四条:为所有导出的API元素编写文档注释

    简而言之,要为API编写文档,文档注释是最好,最有效的途径.对于所有可导出的API元素来说,使用文档注释应该被看作是强制性的.要 采用一致的风格来遵循标准的约定.记住,在文档注释内部出现任何的HTML ...

  6. 1.1 WEB API 在帮助文档页面进行测试

    这篇文章http://www.cnblogs.com/landeanfen/p/5210356.html写得比较详细, 我就挑简单的来说. 首先用这功能要在WEB API创建的帮助文档下面,如果你使用 ...

  7. 使用swagger实现web api在线接口文档

    一.前言 通常我们的项目会包含许多对外的接口,这些接口都需要文档化,标准的接口描述文档需要描述接口的地址.参数.返回值.备注等等:像我们以前的做法是写在word/excel,通常是按模块划分,例如一个 ...

  8. 使用swagger实现web api在线接口文档(转载)

    一.前言 通常我们的项目会包含许多对外的接口,这些接口都需要文档化,标准的接口描述文档需要描述接口的地址.参数.返回值.备注等等:像我们以前的做法是写在word/excel,通常是按模块划分,例如一个 ...

  9. 为ASP.NET WEB API生成人性化说明文档

    一.为什么要生成说明文档 我们大家都知道,自己写的API要供他人调用,就需要用文字的方式将调用方法和注意事项等写成一个文档以更好的展示我们设计时的想法和思路,便于调用者更加高效的使用我们的API. 当 ...

随机推荐

  1. OSG世界坐标转屏幕坐标(转载)

    OSG世界坐标转屏幕坐标 #define M(row,col) m[col * 4 + row] void Transform_Point(double out[4], const double m[ ...

  2. R语言中的if-else语句写法

    结构  1 :  if()  xx  else    yy    一行: 结构  2:   if()  {xx} else  {yy} 或者   if(){ xx }else    #此处不能两行写 ...

  3. css中盒子宽高的auto

    CSS盒模型中,auto属性只适用于外margin和width,height,border和padding不适用.下面就来说说它的情况.这里所说的都是标准流盒子. 1.横向来说 (1)若设置width ...

  4. Bmob 之 列表查询

    查询列表,返回前20个数据: //创建BmobQuery实例,指定对应要操作的数据表名称 BmobQuery *query = [BmobQuery queryWithClassName:classN ...

  5. eclipse安装Veloeclipse(Velocity编辑插件)

    eclipse安装Veloeclipse(Velocity编辑插件) Help-->install new software-->Add 增加 Name:Veloeclipse Value ...

  6. Delphi操作XML

    Delphi操作XML Delphi操作XMl,只要使用 NativeXml.我是用的版本是4..NativeXML的使用方法比较简单,但是功能很强大. XE2的话,要在simdesign.inc后面 ...

  7. jQuery克隆DOM节点

    jQuery克隆DOM节点 <%@ page language="java" import="java.util.*" pageEncoding=&quo ...

  8. oracle与sqlserver利用函数生成年月日加流水号

    最近在做oracle相关的项目,刚接触oracle,与sqlserver语法上还是有区别的 sqlserver : 示例:FX+当前年月日+00001 如下图流水号实力所示 原理: 首先 'FX'是固 ...

  9. Linux笔记(十) - 权限管理

    (1)ACL权限1.查看分区ACL权限是否开启:dumpe2fs -h /dev/sda3-h 仅显示超级块中信息,而不显示磁盘块组的详细信息2.临时开启分区ACL权限:mount -o remoun ...

  10. [TPYBoard-Micropython之会python就能做硬件 3] 制作电子时钟

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.TPYboard V102板  一块 2.DS3231 ...