Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting code into a single line using ReSharper

I am having an issue with formatting code with ReSharper.

I have disabled the option for wrapping lines. With this option, the following code will be formatted to a single line. How can I have ReSharper not format the following code?

Mapper.CreateMap<CountryEntity, Country>()
 .ForMember(dest => dest.CreatedBy, map => map.MapFrom(src => src.CreatedBy))
 .ForMember(dest => dest.DateCreated, map => map.MapFrom(src => src.DateCreated))
 .ForMember(dest => dest.Id, map => map.MapFrom(src => src.Id))
 .ForMember(dest => dest.Name, map => map.MapFrom(src => src.Name))
 .ForMember(dest => dest.CountryCodeChar2, map => map.MapFrom(src => src.CountryCodeChar2))
 .ForMember(dest => dest.CountryCodeChar3, map => map.MapFrom(src => src.CountryCodeChar3));

If I enable line wrapping, the formatted code will come out like this:

Mapper.CreateMap<CountryEntity, Country>().ForMember(
  dest => dest.CreatedBy, map => map.MapFrom(src => src.CreatedBy)).ForMember(
    dest => dest.DateCreated, map => map.MapFrom(src => src.DateCreated)).ForMember(
      dest => dest.Id, map => map.MapFrom(src => src.Id)).ForMember(
        dest => dest.Name, map => map.MapFrom(src => src.Name)).ForMember(
          dest => dest.CountryCodeChar2, map => map.MapFrom(src => src.CountryCodeChar2)).ForMember(
            dest => dest.CountryCodeChar3, map => map.MapFrom(src => src.CountryCodeChar3));

This formatting is also undesirable.

like image 621
chafnan Avatar asked Jan 11 '12 17:01

chafnan


People also ask

How do I add formatting to Visual Studio code?

VS Code has great support for source code formatting. The editor has two explicit format actions: Format Document (Ctrl+Shift+I) - Format the entire active file. Format Selection (Ctrl+K Ctrl+F) - Format the selected text.

How do I beautify the code in IntelliJ?

Go to Settings/Preferences | Editor | Code Style, select your programming language, and open the Wrapping and Braces tab. In the Keep when reformatting section, select the formatting rules which you want to ignore and deselect those which should be applied. Reformat your code ( Ctrl+Alt+L ).


2 Answers

Use Line Breaks and WrappingPreserve Existing FormattingKeep existing line breaks.

like image 183
Jura Gorohovsky Avatar answered Oct 19 '22 09:10

Jura Gorohovsky


Make sure ReSharper → OptionsCode EditingC#Formatting StyleLine Breaks and Wrapping"Wrap Long Lines" is turned off.

like image 23
Jeremy Thompson Avatar answered Oct 19 '22 09:10

Jeremy Thompson