Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Flag optional arguments on methods that differ from their interface declarations

Aberta
#102 5 comentários 0 reações 4 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@GrantErickson já está trabalhando nisso.

Desde 10/4/2020.

Avaliação

Esta issue ainda não foi avaliada.

Descrição

documentation

Consider the following case:

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.
Linguagem predominante
C#
Estrelas
12
Forks
16
Merge médio
5min
PRs com merge (30d)
12

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de IntelliTect/CodingGuidelines

Todas as issues de IntelliTect/CodingGuidelines

Issues semelhantes

Mais issues de C#

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.