10

I read a lot of answers about formatting options for fluent indendation. ( Resharper formatting code into a single line and ReSharper fluent indentation and http://youtrack.jetbrains.com/issue/RSRP-88220 ) like this:

mockCrypto.Expect(c => c.Hash("authenticationHashSalt", "ignoring arguments"))
   .IgnoreArguments()
   .Return("hashed");

But I have not found information about formatting code like this:

kernel.Bind<ICameraController>()
      .To<NikonCameraController>()
      .NamedLikeFactoryMethod((ICameraFactory f) => f.GetNikonCamera());

mock.Setup(framework => framework.DownloadExists("2.0.0.0"))
    .Returns(true)
    .AtMostOnce(); // (it's from moq QuickStart)

But the style is very common and I often see it in the documentation for frameworks. How to set up Resharper auto-formatting for the use of this style?

Community
  • 1
  • 1
Dvor_nik
  • 1,091
  • 1
  • 10
  • 13
  • 4
    I guess this is not possible now. But we are working on it, I hope that this would be done sometime in 7.1-8.0. – Dmitry Osinovskiy Jul 20 '12 at 10:35
  • Thank you for answer. It's good. Resharper is a magical tool, and without this option, but it would be useful. – Dvor_nik Jul 20 '12 at 13:30
  • I personally avoid this style, because renaming the variable causes subsequent lines to become misaligned again. Instead, I put the first `.` on a new line, and indent each line one tab stop as usual. – Michael Liu Jul 27 '12 at 14:31
  • 1
    There is a Code Alignment plugin that works well. http://stackoverflow.com/a/20427618/492 – CAD bloke Mar 31 '15 at 21:24

2 Answers2

3

I'm using next settings in R# in Options -> Code Editing -> C# -> Formatting Style:

Line Breaks and Wrapping -> Arrangement of Member Access Expressions section -> Wrap chained method calls == Chop always

Tabs, Indents, Alignment -> Align Multiple Constructs section -> Chained method calls checked

Result:

enter image description here

Based on https://blog.jetbrains.com/dotnet/2012/11/12/code-formatting-improvements-in-resharper-71/ . Path for Chained method calls was is some version between 7.1 and R# 2018

aderesh
  • 927
  • 10
  • 22
1

Unfortunately, Resharper doesn't seem to be able to do this at the moment and it's an issue that's been flagged for quite some time.

As a potentially acceptable trade off, to minimize the pain of Resharper undoing the formatting of existing fluent invocations, you can select "Keep existing line breaks" in Resharper options under "Formatting Style" -> "Line Breaks and Wrapping" -> "Preserve Existing Formatting".

Matt B
  • 8,315
  • 2
  • 44
  • 65
  • 2
    Is there a similar option for spaces? If I want to make my variable declaration appear as `var thing - - - - - = "hello"` for alignment, how can I stop Resharper undoing it? – Robin Winslow Jan 28 '13 at 13:09