Skip to content

Instantly share code, notes, and snippets.

@diegobersano
Created April 24, 2017 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegobersano/7f2cfe4dfc54a3a27d0072dc3ea58d09 to your computer and use it in GitHub Desktop.
Save diegobersano/7f2cfe4dfc54a3a27d0072dc3ea58d09 to your computer and use it in GitHub Desktop.
namespace WebApi.Areas.HelpPage
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Web.Http.Controllers;
using System.Web.Http.Description;
using System.Xml.XPath;
using WebApi.Areas.HelpPage.ModelDescriptions;
/// <summary>
/// A custom <see cref="IDocumentationProvider"/> that reads the API documentation from an XML documentation file.
/// </summary>
public class XmlDocumentationProvider : IDocumentationProvider, IModelDocumentationProvider
{
private IList<XPathNavigator> _documentNavigator = new List<XPathNavigator>();
// CÓDIGO ADICIONAL DE LA APLICACIÓN
/// <summary>
/// Initializes a new instance of the <see cref="XmlDocumentationProvider"/> class.
/// </summary>
/// <param name="documentPath">The physical path to XML document.</param>
public XmlDocumentationProvider(string documentPath)
{
if (documentPath == null)
{
throw new ArgumentNullException("documentPath");
}
var files = System.IO.Directory.GetFiles(documentPath, "*.xml");
foreach (var file in files)
{
XPathDocument xpath = new XPathDocument(file);
_documentNavigator.Add(xpath.CreateNavigator());
}
}
private XPathNavigator SelectSingleNode(string selectExpression)
{
foreach (var navigator in _documentNavigator)
{
var propertyNode = navigator.SelectSingleNode(selectExpression);
if (propertyNode != null)
return propertyNode;
}
return null;
}
// CÓDIGO ADICIONAL DE LA APLICACIÓN
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment