Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!