Permalink
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (31 sloc) 887 Bytes

RCS1171: Simplify lazy initialization

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

Example

Code with Diagnostic

public object Foo()
{
    if (_foo == null) // RCS1171
    {
        _foo = Initialize();
    }

    return _foo;
}

Code with Fix

public object Foo()
{
    return _foo ?? (_foo = Initialize());
}

See Also

(Generated with DotMarkdown)