All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S4047.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

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

using System;

namespace MyLibrary
{
  public class Foo
  {
    public void Bar(ref object o1, ref object o2) // Noncompliant
    {
    }
  }
}

Compliant solution

using System;

namespace MyLibrary
{
  public class Foo
  {
    public void Bar<T>(ref T ref1, ref T ref2)
    {
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy