Recently, I began to study Roslyn Code analysis. I went through the provided sample codes. My question is this:
Is there a way to get the XML documentation comment for a character loaded from a reference library?
The sample code I worked with is FAQ(7). The goal is to get a comment on the documentation of, say, a function Console.Write.
public void GetWriteXmlComment()
{
var project1Id = ProjectId.CreateNewId();
var document1Id = DocumentId.CreateNewId(project1Id);
var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
var solution = new AdhocWorkspace().CurrentSolution
.AddProject(project1Id, "Project1", "Project1", LanguageNames.CSharp)
.AddMetadataReference(project1Id, mscorlib);
var declarations = SymbolFinder.FindDeclarationsAsync(solution.Projects.First(), "Write", true).Result;
var decFirst = declarations.First();
var commentXml = decFirst.GetDocumentationCommentXml();
}
The sample code works well for some methods - it gets the text of the documentation. But for methods such as Console.Write, it uses NullDocumentationProviderand therefore returns an empty string.
UPDATE
I found that I can load MetadataReferencewith the instance TestDocumentationProvideras follows:
var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location,
default(MetadataReferenceProperties), new TestDocumentationProvider());
where TestDocumentationProviderimplements an abstract class Microsoft.CodeAnalysis DocumentationProvider.
private class TestDocumentationProvider : DocumentationProvider
{
protected override string GetDocumentationForSymbol(string documentationMemberID, CultureInfo preferredCulture, CancellationToken cancellationToken = default(CancellationToken))
{
}
}
, documentationMemberID?