Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DocumentationProvider using NuDoc
namespace Hediet.Reflection
{
interface IDocumentationProvider
{
string GetDocumentationText(MemberInfo memberInfo);
string GetDocumentationText(ParameterInfo memberInfo);
}
class XmlDocumentationProvider : IDocumentationProvider
{
private readonly Dictionary<MemberInfo, Member> documentation = new Dictionary<MemberInfo, Member>();
private Member GetXmlDocumentation(MemberInfo memberInfo)
{
Member member;
if (!documentation.TryGetValue(memberInfo, out member))
{
var r = DocReader.Read(memberInfo.Module.Assembly);
foreach (var element in r.Elements.OfType<Member>())
{
if (memberInfo == element.Info)
{
member = element;
break;
}
}
documentation.Add(memberInfo, member);
}
return member;
}
public string GetDocumentationText(MemberInfo memberInfo)
{
var member = GetXmlDocumentation(memberInfo);
if (member == null)
return null;
var summary = member.Elements.OfType<Summary>().FirstOrDefault();
if (summary == null)
return null;
return summary.ToText();
}
public string GetDocumentationText(ParameterInfo parameterInfo)
{
var member = GetXmlDocumentation(parameterInfo.Member);
if (member == null)
return null;
var summary = member.Elements.OfType<Param>().FirstOrDefault(p => p.Name == parameterInfo.Name);
if (summary == null)
return null;
return summary.ToText();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.