rspec/rules/S4047/csharp/rule.adoc

52 lines
989 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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++``.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
using System;
namespace MyLibrary
{
public class Foo
{
public void Bar(ref object o1, ref object o2) // Noncompliant
{
}
}
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
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)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]