Receive the documentation/common field
-
There's a field class, field has a description.
Example
Public Class ElementBT3
''' <summary> ''' [Выравнивание] ''' Сдвинуть элемент влево ''' </summary> ''' <remarks></remarks> Public hasClassPullLeft As Boolean = False
End Class
I'm taking the fields.
For Each fi As FieldInfo In obj.GetType().GetFields
Next
Question of how to obtain the text of the commentary
''' <summary>
''' [Выравнивание]
''' Сдвинуть элемент влево
''' </summary>
''' <remarks></remarks>
UPDATE
Added the attribute.
<Description("[Выравнивание] Сдвинуть элемент влево")> _
Public hasClassPullLeft As Boolean = False
How do we get it now?
♪Attributes
Nothing, something strange.Public {6}
-
I don't think so. XML comments are not retained in the reference code. But if you want to, there are a few options to solve the problem. For example, an external file could be developed at the project assembly stage, which would contain XML comments. Either if you have access to the source(s) you can use Roslyn for comment.
This is an example with Roslyn:
using Roslyn.Compilers.CSharp; using System; using System.Linq;
class Program
{
static void Main(string[] args)
{
var tree = SyntaxTree.ParseText(@"
/// <summary>This is an xml doc comment</summary>
class C
{
}");
var classNode = (ClassDeclarationSyntax)tree.GetRoot().Members.First();
var trivia = classNode.GetLeadingTrivia().Single(t => t.Kind == SyntaxKind.DocumentationCommentTrivia);
var xml = trivia.GetStructure();
Console.WriteLine(xml);var compilation = Compilation.Create("test", syntaxTrees: new[] { tree }); var classSymbol = compilation.GlobalNamespace.GetTypeMembers("C").Single(); var docComment = classSymbol.GetDocumentationComment(); Console.WriteLine(docComment.SummaryTextOpt); }
}
As a simpler option, you can use the attributes to keep the description to the methods:
[Display(Name = "Foo", Description = "Blah")]
void Foo()
{
}