Permalink
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (50 sloc) 1.1 KB

RCS1210: Return Task.FromResult instead of returning null

Property Value
Id RCS1210
Category Usage
Default Severity Warning
Enabled by Default
Supports Fade-Out -
Supports Fade-Out Analyzer -

Examples

Code with Diagnostic

Task<object> GetAsync()
{
    return null; // RCS1210
}

Code with Fix

Task<object> GetAsync()
{
    return Task.FromResult<object>(null);
}

Code with Diagnostic

Task<object> GetAsync()
{
    return _foo?.GetAsync(); // RCS1210
}

Code with Fix

Task<object> GetAsync()
{
    Foo x = _foo;
    if (x != null)
    {
        return _foo.GetAsync();
    }
    else
    {
        return Task.FromResult<object>(null);
    }
}

See Also

(Generated with DotMarkdown)