Skip to content

?. (null conditional) operator and newlines #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lemtzas opened this issue Apr 29, 2016 · 2 comments
Open

?. (null conditional) operator and newlines #74

lemtzas opened this issue Apr 29, 2016 · 2 comments

Comments

@lemtzas
Copy link

lemtzas commented Apr 29, 2016

This is the chained-statement break-style my group's codebase has been following:

var hereAreSometThings =
    what.Wonderful.Things
    .Select(thing => thing.OtherThing)
    .Select(this.TransformThing)
    .ToList();

Which I find quite readable.

But Things is sometimes null. And we're on C# 6 now.

So I threw a ?. in the obvious place:

var hereAreSometThings =
    what.Wonderful.Things
    ?.Select(thing => thing.OtherThing)
    .Select(this.TransformThing)
    .ToList();

I still find this quite readable (though perhaps a bit weird now that the alignment is off)

But stylecop became quite unhappy with the spacing around ?., throwing a SA1003 : CSharp.Spacing : The spacing around the symbol '?.' is invalid.

It does, however, find the following things acceptable:

var hereAreSometThings =
    what.Wonderful.Things?.
    Select(thing => thing.OtherThing)
    .Select(this.TransformThing)
    .ToList();

var hereAreSometThings =
    what.Wonderful
    .Things?.Select(thing => thing.OtherThing)
    .Select(this.TransformThing)
    .ToList();

I find both of those options pretty unfortunate. In both cases I kinda gloss over the ?. operator, which was so obvious in the other layout. To say nothing of the inconsistency with my group's existing style.

I went to go disable the check, but it seems it would be even more unfortunate to turn off SA1003.

@adamralph
Copy link

adamralph commented May 2, 2016

This is already fixed in https://stylecop.codeplex.com/ - version 4.7.53.0

@lemtzas
Copy link
Author

lemtzas commented May 3, 2016

Ah. Thanks for the reply. Will use that instead.

On Mon, May 2, 2016, 08:26 Adam Ralph [email protected] wrote:

This is already fixed in https://stylecop.codeplex.com/


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#74 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants