Rendering constants into XML documentation?

Add a summary to each constant containing the value, then refer to those comments:

/// <summary>24</summary>
private const byte _minAge = 24;
/// <summary>29</summary>
private const byte _maxAge = 29;

/// <summary>Checks whether the age is within the allowed range (between <inheritdoc cref="_minAge"/> and <inheritdoc cref="_maxAge"/>).</summary>
public bool IsInAgeRange() { ... }

I know it’s still duplication, but this way you can keep your constant comments near your constants, also if the constants are defined in another file entirely.

Leave a Comment