rspec/rules/S4018/rule.adoc
Zsolt Kolbay dc26f15566
Modify rule S4018: modify message to make it clear the rule is about type inference (#1503)
* Fix S4018 message to make it clear it's about type inference.

* Added more comments to code sample.

* And more...

* Updated message to include refactoring.
2023-01-16 15:22:23 +01:00

42 lines
692 B
Plaintext

Type inference enables the call of a generic method without explicitly specifying its type arguments. This is not possible when a parameter type is missing from the argument list.
== Noncompliant Code Example
[source,text]
----
using System;
namespace MyLibrary
{
public class Foo
{
public void MyMethod<T>() // Noncompliant
{
// this method can only be invoked by providing the type argument e.g. 'MyMethod<int>()'
}
}
}
----
== Compliant Solution
[source,text]
----
using System;
namespace MyLibrary
{
public class Foo
{
public void MyMethod<T>(T param)
{
// type inference allows this to be invoked 'MyMethod(arg)'
}
}
}
----