简体   繁体   中英

How to stop Resharper from line breaking after return keyword for long lines?

When I auto format with Resharper CTRL + ALT + SHIFT + F for lines longer than max line length (in my case say it's 80 characters), I get the following:

    return
        View(new ViewModel
        {
            Identifier = identifier,
            Files = service.AllFiles()
        });

But what I really want is it not to wrap after the "return" keyword (ie not have the return keyword on a line all on its own), like so:

    return View(new ViewModel
    {
        Identifier = identifier,
        Files = service.AllFiles()
    });

Does anyone know how to "configure" Resharper to make this happen? :)

Here's another example, here's what I'm seeing now:

    return
        repository.Session.CreateCriteria(typeof(SomeType))
                  .Add(Expression.Eq("Identifier", identifier))
                  .UniqueResult<SomeType>();

When I really want to see:

    return repository.Session.CreateCriteria(typeof(SomeType))
                     .Add(Expression.Eq("Identifier", identifier))
                     .UniqueResult<SomeType>();

UPDATE:

Here is "chop always":

    return View(new OrganisationFileLoadViewModel
    {
        Identifier = identifier,
        AllExistingOrganisationFiles = nmdsOrganisationFileLoadService.AllNMDSOrganisationFiles()
    });

Here is "chop if long":

    return
        View(new OrganisationFileLoadViewModel
        {
            Identifier = identifier,
            AllExistingOrganisationFiles = nmdsOrganisationFileLoadService.AllNMDSOrganisationFiles()
        });

Resharper -> Options -> (Code Editing) C# -> Formatting Style -> Line Breaks and Wrapping

There are a lot of settings for line wrapping. The default for Wrap long lines is normally 120 characters. This may be triggering your break since you are set to 80 or Resharper 8.0 may have a newer option for return. The path above is for 7.0, but I believe it is the same or at least similar to 8.0.

The nice is that they show you examples for the changes you make so you don't have to test it right away.

There is no special option to turn "wrapping after return" OFF.

1) I was not able to reproduce a similar code formatting as shown in the first code snippet. However, I recommend you trying to change this setting to "Simple Wrap": ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Wrap invocation arguments ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Wrap invocation arguments ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Wrap invocation arguments .

2) In my case, the following changing helps me: ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Wrap chained method calls | Select "Chop always" ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Wrap chained method calls | Select "Chop always" ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Wrap chained method calls | Select "Chop always" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM