Skip to content

destructor-summary-standard-text

C#stylefix: unsafedefault: offcsharp/stylecop

Reports the summary of a finalizer that does not start with “Finalizes an instance of the <see cref="T"/> class.” The <see> is compared with the name of the type. The fix puts the standard sentence before the text and is unsafe.

A finalizer is called by the runtime and not by code, so there is nothing to say about how it is used. The standard sentence gives every finalizer the same first line, and the text after it adds what the finalizer cleans up.

Reported
...
/// <summary>Destructors.</summary>
public class DestructorsWrong
{
/// <summary>Cleans up.</summary>
~DestructorsWrong() { }
}
/// <summary>Destructors.</summary>
public class DestructorsOther
{
/// <summary>Finalizes an instance of the <see cref="Other"/> class.</summary>
~DestructorsOther() { }
}
/// <summary>Destructors.</summary>
...
/// <summary>Destructors.</summary>
public class DestructorsNoPeriod
{
/// <summary>Finalizes an instance of the <see cref="DestructorsNoPeriod"/> struct.</summary>
~DestructorsNoPeriod() { }
}
/// <summary>Other.</summary>
...
After the fix
...
/// <summary>Destructors.</summary>
public class DestructorsWrong
{
/// <summary>Finalizes an instance of the <see cref="DestructorsWrong"/> class. Cleans up.</summary>
~DestructorsWrong() { }
}
/// <summary>Destructors.</summary>
public class DestructorsOther
{
/// <summary>Finalizes an instance of the <see cref="DestructorsOther"/> class.</summary>
~DestructorsOther() { }
}
/// <summary>Destructors.</summary>
...
/// <summary>Destructors.</summary>
public class DestructorsNoPeriod
{
/// <summary>Finalizes an instance of the <see cref="DestructorsNoPeriod"/> class.</summary>
~DestructorsNoPeriod() { }
}
/// <summary>Other.</summary>
...
csharp:
lint:
rules:
destructor-summary-standard-text: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line destructor-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 SA1643 partial the <see cref> is compared with the name of the type by spelling, not resolved; other cultures’ texts are not available