Permalink
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (27 sloc) 868 Bytes

RCS1180: Inline lazy initialization

Property Value
Id RCS1180
Category Simplification
Default Severity Info
Enabled by Default
Supports Fade-Out -
Supports Fade-Out Analyzer -

Example

Code with Diagnostic

List<object> items = null;

// ...

if (items == null) // RCS1180
{
    items = new List<object>();
}

items.Add(x);

Code with Fix

(items ?? (items = new List<object>())).Add(x);

See Also

(Generated with DotMarkdown)