Created
April 24, 2017 00:35
-
-
Save diegobersano/7f2cfe4dfc54a3a27d0072dc3ea58d09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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