rspec/rules/S4047/csharp/rule.adoc
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

64 lines
1.1 KiB
Plaintext

== Why is this an issue?
When a reference parameter (keyword ``++ref++``) is used, the passed argument type must exactly match the reference parameter type. This means that to be able to pass a derived type, it must be cast and assigned to a variable of the proper type. Use of generic methods eliminates that cumbersome down casting and should therefore be preferred.
This rule raises an issue when a method contains a ``++ref++`` parameter of type ``++System.Object++``.
=== Noncompliant code example
[source,csharp]
----
using System;
namespace MyLibrary
{
public class Foo
{
public void Bar(ref object o1, ref object o2) // Noncompliant
{
}
}
}
----
=== Compliant solution
[source,csharp]
----
using System;
namespace MyLibrary
{
public class Foo
{
public void Bar<T>(ref T ref1, ref T ref2)
{
}
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Make this method generic and replace the "object" parameter with a type parameter.
=== Highlighting
Primary: Method definition
Secondary: noncompliant parameter
endif::env-github,rspecator-view[]