Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda