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?