2023-05-03 11:06:20 +02:00
== Why is this an issue?
2023-01-16 15:22:23 +01:00
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.
2020-06-30 12:49:37 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:49:37 +02:00
----
using System;
namespace MyLibrary
{
public class Foo
{
public void MyMethod<T>() // Noncompliant
{
2023-01-16 15:22:23 +01:00
// this method can only be invoked by providing the type argument e.g. 'MyMethod<int>()'
2020-06-30 12:49:37 +02:00
}
}
}
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:49:37 +02:00
----
using System;
namespace MyLibrary
{
public class Foo
{
public void MyMethod<T>(T param)
{
2023-01-16 15:22:23 +01:00
// type inference allows this to be invoked 'MyMethod(arg)'
2020-06-30 12:49:37 +02:00
}
}
}
----