Formatting method call arguments that include anonymous delegate

I am using RS 5.0 in VS 2010 and am getting some formatting results I don't like, but can't seem to configure otherwise.  I want to align my call arguments each on  a separate line, I can get this to work fine if all the arguments are references or literals but as soon as I use an anonymous delegate (or equivalent lambda) the delegate does not get aligned as I would expect.

I enter something like this with my system configured to format on entry of the semi-colon:

serviceClient.BeginMyOperation((ar) => {}, null);

and I get this:

serviceClient.BeginMyOperation((ar) =>

{

},

                                                 null);

when what I really want is

serviceClient.BeginMyOperation((ar) =>

                                             {

                                             },

                                             null);

where the braces for the delegate are aligned with start of the argument and not at the start of the line.

Is there a way to get RS to format like this.

I can of course manually format it but as soon as I use the Code Cleanup formatting option it gets put back.

Mike Hanson

4 comments

Update on this.  I have discovered that the formatting sort of works if the anonymous delegate is not the first

argument.

So if I enter something like this:

serviceClient.BeginMyOperation("literal", (ar) => {}, null);

I get this:

serviceClient.BeginMyOperation("literal",

                                             (ar) =>

                                             {

                                             },

                                             null);

The only issue here is that if the anonymous delegate contains implemenation code it does not get indented.

So this:

serviceClient.BeginMyOperation("literal", (ar) => { doThis(); doThat(); }, null);

produces:

serviceClient.BeginMyOperation("literal",

                                             (ar) =>

                                             {

                                             doThis();

                                             doThat();

                                             },

                                             null);

instead of:

serviceClient.BeginMyOperation("literal",

                                             (ar) =>

                                             {

                                                  doThis();

                                                  doThat();

                                             },

                                             null);

Mike

0

Speaking of formatting, are there any plans to allow object initializers to
be formatted this way? This is actually how Visual Studio 2008/2010 format
out of the box and I prefer it this way. Just seems cleaner to me.

var collection = new
{
     "one",
     "two",
     "three"
};

I may be mistaken, but this actually looks closer to the K&R standard than
with the braces aligned under the new keyword.

"Mike Hanson" <no_reply@jetbrains.com> wrote in message
news:7578916.29211259487543691.JavaMail.clearspace@app8.labs.intellij.net...

I am using RS 5.0 in VS 2010 and am getting some formatting results I
don't like, but can't seem to configure otherwise.  I want to align my
call arguments each on  a separate line, I can get this to work fine if
all the arguments are references or literals but as soon as I use an
anonymous delegate (or equivalent lambda) the delegate does not get
aligned as I would expect.

>

I enter something like this with my system configured to format on entry
of the semi-colon:

>

serviceClient.BeginMyOperation((ar) => {}, null);

>

and I get this:

>

serviceClient.BeginMyOperation((ar) =>
{

>

},
                                                 null);

>

when what I really want is

>

serviceClient.BeginMyOperation((ar) =>
                                             {

>

                                             },
                                             null);

>

where the braces for the delegate are aligned with start of the argument
and not at the start of the line.

>

Is there a way to get RS to format like this.

>

I can of course manually format it but as soon as I use the Code Cleanup
formatting option it gets put back.

>

Mike Hanson

>
>
>
>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5251195#5251195


0

Hello Greg
     Have you tried turning off the 'Indent object/array/collection initializer' option under ReSharper > Options > Languages > C# > Code Style > Other? Thank you!

Andrey Serebryansky

Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0

I have that option disabled already, thanks for the response anyway.

0

Please sign in to leave a comment.