If I have a positional record like this:
public record Version(int Major, int Minor);
it seems that I can only provide a <summary>
documentation, like this:
/// <summary>
/// Version record
/// </summary>
public record Version(int Major, int Minor);
Is it possible to document the Major
and Minor
properties (possibly constructor arguments as well) while keeping the short record syntax?
As canton7 points out this is still under development.
The best workaround right now to document the property and the parameters is to define the property explicitly, whilst keeping the record positional:
/// <summary>
/// Version record
/// </summary>
/// <param name="Major">Major constructor parameter</param>
/// <param name="Minor">Minor constructor paramater</param>
public record Version(int Major, int Minor)
{
/// <summary>
/// Major Property
/// </summary>
public int Major { get; init; } = Major;
/// <summary>
/// Minor property
/// </summary>
public int Minor { get; init; } = Minor;
}
This is slightly shorter than defining the constructor yourself, but more usefully, once support is added you can move the documentation to the primary constructor whilst knowing that this won't change the generated code in any way. Also it is necessary to do it this way if you want to inherit from another positional record.
You can document it like this :
/// <summary>
/// Version record
/// </summary>
/// <param name="Major">Major version</param>
/// <param name="Minor">Minor version</param>
public record Version(int Major, int Minor);
And then you have the documentation while using it in-code :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With