Ternary operator and other questions
Hello, I am a new user of resharper, and I'm trying to customize it to my code style. One thing I'm having trouble with is tenary operators. For simple ternary operators I'd like to have the following formatting:
condition? expr1 : expr2;
or if that is too long, wrap as
condition ?
expression1 :
expression2;
Maybe I just didn't figure out what options to select, but when I apply code formatting, Resharper always does
condition
? expression1
: expression2
Also sometimes I chain ternary operators like so:
condition ? expression 1 :
condition2 ? expression 2 :
condition3 ? expression 3 :
expression4;
Again resharper doesn't do what I want:
condition
? expression1
: condition2
? expression 2
: condition3 (etc.)
Another question I have is the use of the var keyword. I've decided to disable the rule because sometimes I choose not use var. My rule is actually pretty simple: I use var anywhere I can, except for built-in numerical types (int, float, byte, etc.) Is there a way to create such a rule in Resharper?
Also, is there a way to apply code cleanup on an entire project or solution, rather than file by file?
That'll be it for now :p, thanks!
Please sign in to leave a comment.
Hello
Thank you very much for feedback! Regarding your questions:
1. At the moment it's not possible to control the placement of '?' when ReSharper wraps ternary expressions.
2. With ReSharper you can either use var for everything except all built-in types or for everything except simple types. See ReSharper | Options | Code Editing | Code Cleanup
3. You can apply code cleanup to project/solution by right clicking the corresponding node in Solution Explorer and then clicking 'Cleanup Code'
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Is there a feature request for this? I have never seen ternary operators formatted the way Resharper forces me to & would very much like to control this. I've seen this mentioned elsewhere as a desired feature. Thanks...