Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
Limit private method to only be called by specific method

This might sound crazy but hear me out...

I have a method that violates https://rules.sonarsource.com/csharp/RSPEC-4457

Parameter validation in "async"/"await" methods should be wrapped

...split the method into two: an outer method handling the parameter checks (without being async/await) and an inner method to handle the iterator block with the async/await pattern...

An async Task that checks the arguments and performs async logic

So I've split the method into two as it suggests, one checking for null arguments and one performing the logic

private Task ThisMethod(string value) {
    if(value == null)
      throw new ArgumentException(nameof(value));

    return ThisMethodAsync(value);
}

private async Task ThisMethod(string value) {
    //async logic
}

The problem I now have is that really I don't want that second method to ever be called in isolation as the checks won't be performed, I want it to be one logical method but have split as suggested

Is there a way to limit this second method from being called at all unless being called from the first method? A nifty attribute I'm unaware of perhaps? A stricter than private access modifier?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda