Skip to content

constructor-summary-standard-text

C#stylefix: unsafedefault: offcsharp/stylecop

Reports the summary of a constructor that does not start with the standard sentence: “Initializes a new instance of the <see cref="T"/> class” (or “struct”), “Initializes static members of the …” for a static constructor. A private constructor may say “Prevents a default instance of the … from being created”. The <see> is compared with the name of the type. The fix puts the standard sentence before the text and is unsafe.

A constructor needs no description of what it does that every constructor does not already say; the standard sentence gives the same first line to all of them, and the text after it adds what is special about this one. Many documentation conventions require it.

Reported
...
{
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class.</summary>
public Constructors() { }
/// <summary>Creates it.</summary>
public Constructors(int a) { }
/// <summary>Initializes a new instance of the <see cref="Other"/> class.</summary>
public Constructors(int a, int b) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> struct.</summary>
public Constructors(int a, int b, int c) { }
/// <summary>Initializes a new instance of the Constructors class.</summary>
public Constructors(long a) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class and more.</summary>
public Constructors(long a, long b) { }
...
private Constructors(char a, char b) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class.</summary>
private Constructors(char a, char b, char c) { }
/// <summary>Private.</summary>
private Constructors(char a, char b, char c, char d) { }
/// <summary>Prevents a default instance of the <see cref="Constructors{T}"/> class from being created.</summary>
protected Constructors(byte a) { }
/// <summary>Finalizes an instance of the <see cref="Constructors{T}"/> class.</summary>
~Constructors() { }
...
After the fix
...
{
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class.</summary>
public Constructors() { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class. Creates it.</summary>
public Constructors(int a) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class.</summary>
public Constructors(int a, int b) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class.</summary>
public Constructors(int a, int b, int c) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class. Initializes a new instance of the Constructors class.</summary>
public Constructors(long a) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class and more.</summary>
public Constructors(long a, long b) { }
...
private Constructors(char a, char b) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class.</summary>
private Constructors(char a, char b, char c) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class. Private.</summary>
private Constructors(char a, char b, char c, char d) { }
/// <summary>Initializes a new instance of the <see cref="Constructors{T}"/> class. Prevents a default instance of the <see cref="Constructors{T}"/> class from being created.</summary>
protected Constructors(byte a) { }
/// <summary>Finalizes an instance of the <see cref="Constructors{T}"/> class.</summary>
~Constructors() { }
...
csharp:
lint:
rules:
constructor-summary-standard-text: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line constructor-summary-standard-text in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
StyleCop SA1642 partial the <see cref> is compared with the name of the type by spelling, not resolved (a cref through a using alias or a different qualification of the same type is not recognized); other cultures’ texts are not available