csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Potential new ternary formatting

Open belav opened this issue 9 months ago • 0 comments

The current formatting of nested ternary operators

var languageCode = something.IsNotBlank()
    ? something
    : otherThing.IsNotBlank()
        ? otherThing
        : thingThing.IsNotBlank()
            ? thingThing
            : "enUs";

If that were to change to this, then I believe it becomes a lot more readable.

var languageCode = 
    something.IsNotBlank() ? something
    : otherThing.IsNotBlank() ? otherThing
    : thingThing.IsNotBlank() ? thingThing
    : "enUs";

Would also need to consider what to do if someone creates a statement like this

var x = firstCondition
    ? secondCondition
        ? firstValue
        : secondValue
    : thirdCondition
        ? thirdValue
        : fourthValue;

belav avatar May 07 '24 20:05 belav