no-default-value-type-constructor
What it does
Section titled “What it does”Reports new S() of a value type that has an implicit parameterless constructor and no initializer: write default(S), or the named constant where there is one (Guid.Empty, CancellationToken.None, IntPtr.Zero, the enum member with value 0). No fix for a target-typed new().
Why it matters
Section titled “Why it matters”new S() of such a struct is the zero value, the same as default(S), but it reads as a call that does something. default states that the value is the zero value, and a named constant (Guid.Empty) says what that value means.
To fix, write default(S) or the constant.
Example
Section titled “Example”... var s = new S(); var d = new DateTime();... Debug.Assert(true, "why");...... var s = default(S); var d = default(DateTime);... Debug.Assert(true, "why");...Configuration
Section titled “Configuration”csharp: lint: rules: no-default-value-type-constructor: warn # off (default), warn, errorEnabled by the presets: csharp/stylecop.
Suppress one line with sudsy-disable-next-line no-default-value-type-constructor in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| StyleCop | SA1129 |
full |