Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

56 lines
1.6 KiB
Plaintext

== Why is this an issue?
Passing a parameter by reference, which is what happens when you use the ``++out++`` or ``++ref++`` parameter modifiers, means that the method will receive a pointer to the argument, rather than the argument itself. If the argument was a value type, the method will be able to change the argument's values. If it was a reference type, then the method receives a pointer to a pointer, which is usually not what was intended. Even when it is what was intended, this is the sort of thing that's difficult to get right, and should be used with caution.
This rule raises an issue when ``++out++`` or ``++ref++`` is used on a non-``++Optional++`` parameter in a public method. ``++Optional++`` parameters are covered by S3447.
=== Noncompliant code example
[source,csharp]
----
public void GetReply(
ref MyClass input, // Noncompliant
out string reply) // Noncompliant
{ ... }
----
=== Compliant solution
[source,csharp]
----
public string GetReply(MyClass input)
{ ... }
public bool TryGetReply(MyClass input, out string reply)
{ ... }
public ReplyData GetReply(MyClass input)
{ ... }
internal void GetReply(ref MyClass input, out string reply)
{ ... }
----
=== Exceptions
This rule will not raise issues for:
* non-public methods
* methods with only 'out' parameters, name starting with "Try" and return type bool.
* interface implementation methods
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Consider refactoring this method in order to remove the need for this "[out|ref]" modifier.
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]