84 lines
1.4 KiB
Plaintext
84 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
include::description.adoc[]
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
public Result[] GetResults()
|
|
{
|
|
return null; // Noncompliant
|
|
}
|
|
|
|
public IEnumerable<Result> GetResults(bool condition)
|
|
{
|
|
var results = GenerateResults();
|
|
return condition
|
|
? results
|
|
: null; // Noncompliant
|
|
}
|
|
|
|
public IEnumerable<Result> GetResults() => null; // Noncompliant
|
|
|
|
public IEnumerable<Result> Results
|
|
{
|
|
get
|
|
{
|
|
return default(IEnumerable<Result>); // Noncompliant
|
|
}
|
|
}
|
|
|
|
public IEnumerable<Result> Results => default; // Noncompliant
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
public Result[] GetResults()
|
|
{
|
|
return new Result[0];
|
|
}
|
|
|
|
public IEnumerable<Result> GetResults(bool condition)
|
|
{
|
|
var results = GenerateResults();
|
|
return condition
|
|
? results
|
|
: Enumerable.Empty<Result>();
|
|
}
|
|
|
|
public IEnumerable<Result> GetResults() => Enumerable.Empty<Result>();
|
|
|
|
public IEnumerable<Result> Results
|
|
{
|
|
get
|
|
{
|
|
return Enumerable.Empty<Result>();
|
|
}
|
|
}
|
|
|
|
public IEnumerable<Result> Results => Enumerable.Empty<Result>();
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
Although ``++string++`` is a collection, the rule won't report on it.
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|