csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Long expression IsPattern breaking

Open belav opened this issue 4 years ago • 2 comments

The following

        if (
            someLongName____________________________________________________ is
            { } anotherLongName______________________
        ) {
            return;
        }

Is more readable as

        if (
            someLongName____________________________________________________
            is { } anotherLongName______________________
        ) {
            return;
        }

belav avatar Sep 06 '21 18:09 belav

real world example

            if (
                parameterCustomAttributes.OfType<IFromRouteMetadata>().FirstOrDefault() is
                { } routeAttribute
            ) {

belav avatar Sep 06 '21 19:09 belav

make sure to test with

        if (
            context.ActionDescriptor is ControllerActionDescriptor
            {
                ActionName: "Post" or "Patch" or "Delete"
            }
        ) { }
        if (
            context.ActionDescriptor is ControllerActionDescriptor
            {
                ActionName: "MuchLongerStringValue"
                    or "MuchLongerStringValue"
                    or "MuchLongerStringValue"
            }
        ) { }

belav avatar Dec 20 '21 19:12 belav