code documentation, get value from constant
Asked Answered
P

1

7

Is it possible, that having a constant

 public const string MyString = "myValue"

to get its value "myValue" in xml comments ? I'm interested in this for generating swagger documentation.

    /// <summary>
    /// Creates a new resource.
    /// </summary>
    /// <param name="request">The request object.</param>
    /// <returns code="200">The id of the new resource.</returns>
    /// <response code="400">
    /// <see cref="Errors.BadRequestCodes.MyString"/><para/>
    /// </response>

This is an example of a documented endpoint. And in the swagger ui, instead of seeing the message "myValue" on the 400 status code section I'm actually seeing "Errors.BadRequestCodes.MyString". Is there any way of achieving this?

Pelican answered 1/3, 2021 at 8:28 Comment(1)
The intention behind most of these questions about XML doc, seems to be to avoid string duplication. I found no way around this yet. I would like to use the text from a code attribute also for the doc, e.g. [Description("This property is about blah blah")], to be displayed in some tool, and a property XML doc like /// <summary>This property is about blah blah</summary> , without duplicating the string text.Savadove
D
3

Have you tried using <inheritdoc>, and just adding the const value in the first file and then referring to it in the second?

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/inheritdoc

Rendering constants into XML documentation?

Demodulation answered 1/3, 2021 at 8:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.