I want to read at runtime the summary text from the class
/// <summary>
/// Text I want to get 1
/// </summary>
class Hello
{
/// <summary>
/// Text I want to get 2
/// </summary>
string name {get;set;}
}
static void Main(string[] args)
{
}
is that possible ?
I expect to have a dictionary or something else that contains the name of class or the property and his summary something like this.
Dictionary<string, string> Dic ;
for example : {("Hello", "Text i want to get 1"),("name", "Text i want to get 2")}
Not a full answer but some steps helping to achieve your goal.
First of all you will need to enable generating the documentation file. Add the following to the .csproj file:
Which will generate the file named
{AssemblyName}.xmlin the output folder (docs):which you then will be able to access for example via the following (sample):
Then comes the hard part - parsing the file, which will look something like the following (for the sample code):
This task is actually already done by
Swashbucklewhich can use xml comments to to generate Swagger descriptions, so I strongly suggest to look at how they are doing it - see Swashbuckle.AspNetCore.SwaggerGen/XmlComments for example.Another option is to look into source generators which allow to analyze your codebase (including XML comments) and generate some code files which will be compiled into the assembly.