IntelliTect / IntelliTect/CodingGuidelines

Flag optional arguments on methods that differ from their interface declarations

Abierto
#102 5 comentarios 0 reacciones 4 asignados Reclamado por @GrantErickson Ver en GitHub
documentation
Lenguaje dominante
C#
Estrellas
12
Forks
16
Merge medio
2 min
PR fusionados (30 d)
7

Descripción

Consider the following case:
```C#
public class Foo : IFoo
{
public void Bar(int value = 2) => Console.WriteLine(value);
}
public interface IFoo
{
public void Bar(int value = 1);
}

public static void Main(string[] args)
{
IFoo foo1 = new Foo();
foo1.Bar();
var foo2 = new Foo();
foo2.Bar();
}
```
Output:
```
2
1
```

I would propose that the coding standard be
```
DO NOT: declare optional arguments on class methods that are implementing an interface.
```
Rational:
- If these value are not in sync it will cause behavior as shown above.
- It is possible to declare a constant and share it in both places. However, if you have an interface for accessing the class, why is there code bypassing it? If you want to invoke the method using the default value, simply go through the interface.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.