Skip to main content

RCS1210: Return completed task instead of returning null

Properties

PropertyValue
Default SeverityWarning
Minimum language version-

Examples

Example #1

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

Example #2

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

Applies to