I can declare a C# positional record like this:
public record Box(double Capacity);
which results in the definition of a record class named Box
with a property named Capacity
, as well as a primary constructor for Box
that takes a parameter named Capacity
. Now I want to be able to create independent documentation comments for all four of these items:
- The record type
Box
. - The property
Capacity
. - The primary constructor.
- The constructor parameter
Capacity
.
If I create a documentation comment like this:
/// <summary>
/// A container for items.
/// </summary>
/// <param name="Capacity">How much the Box can hold</param>
public record Box(double Capacity);
then I get the same summary comment for both the Box
type and the constructor, and the same parameter comment for both the Box
property and the constructor parameter.
As discussed in this question, I can create independent comments for the property and the constructor parameter by explicitly declaring the property:
/// <summary>
/// A container for items.
/// </summary>
/// <param name="Capacity">Specifies the size of the box</param>
public record Box(double Capacity) {
/// <summary>
/// Returns the size of the box.
/// </summary>
public double Capacity { get; init; } = Capacity;
}
And I can create independent comments for all of the parts by explicitly declaring the constructor as well:
/// <summary>
/// A container for items.
/// </summary>
public record Box {
/// <summary>
/// Returns the size of the box.
/// </summary>
public double Capacity { get; init; }
/// <summary>
/// Creates a new Box instance.
/// </summary>
/// <param name="Capacity">Specifies the size of the box</param>
public Box(double Capacity) {
this.Capacity = Capacity;
}
}
But now I have completely lost the syntactic elegance of the record type! Is there any way to retain the concise record declaration with positional parameters while generating independent documentation comments for all of its generated parts?