C
C#16mo ago
blokyk

✅ Disable IDE0046 (use conditional return) when throw is involved

Hello, I was wondering if there is any way to disable "Use conditional return" when half of the expression is a throw expression? I'm not too well-versed when it comes to fine-grained .editorconfig stuff... Example code:
if (arg > 5) // IDE0046: Use conditional return
throw new Exception("some long message");

return DoSomeStuff(arg);

// Code fix suggestion:
return arg > 5 ? throw new Exception(...) : DoSomeStuff(arg);
if (arg > 5) // IDE0046: Use conditional return
throw new Exception("some long message");

return DoSomeStuff(arg);

// Code fix suggestion:
return arg > 5 ? throw new Exception(...) : DoSomeStuff(arg);
4 Replies
blokyk
blokykOP16mo ago
Or for that matter, is there a way to limit the "depth" of the it? Cause it often suggest folding multiple conditions one after another, ending up with a chain of 2 or 3 nested conditional expression that becomes unreadable :/
333fred
333fred16mo ago
I don't believe there's any more specific options for that fixer, but maybe @Metasyntactic has a better idea
Metasyntactic
Metasyntactic16mo ago
There is no way to change this. You can always suppress or ignore in places where you don't like it
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server