t2035816
t2035816

Reputation: 37

Fixing line breaks in methods with Resharper?

I have this method that I don't really know what to do with. I know resharper offers some sort of functionality to format it better, obviously the first if statement should be an extra line break away from the first line WriteString method, and inside the else the first else should be an extra line break away from WriteInteger(item.Data.SpriteId);

Hopefully you can get what I'm trying to do just from that short explanation... If I run a code clean up on Resharper I know it doesn't do this from past experiences, does anyone know how I can configure this?

An example, this code below...

public void DoSomething() {
    WriteString(item.Data.Type.ToString());
    if (item.Data.Type.ToString().ToLower() == "b")
    {
        WriteString(item.Data.ItemName);
    }
    else
    {
        WriteInteger(item.Data.SpriteId);
        if (item.Data.InteractionType == InteractionType.WALLPAPER || item.Data.InteractionType == InteractionType.FLOOR || item.Data.InteractionType == InteractionType.LANDSCAPE)
        {
            WriteString(item.Name.Split('_')[2]);
        }
        else if (item.Data.InteractionType == InteractionType.BOT) //Bots
        {
            WriteString(!PlusEnvironment.GetGame().GetCatalog().TryGetBot(item.ItemId, out var catalogBot) ? "hd-180-7.ea-1406-62.ch-210-1321.hr-831-49.ca-1813-62.sh-295-1321.lg-285-92" : catalogBot.Figure);
        }
        else if (item.ExtraData != null)
        {
            WriteString(item.ExtraData ?? string.Empty);
        }
        WriteInteger(item.Amount);
        WriteBoolean(item.IsLimited);
        if (item.IsLimited)
        {
            WriteInteger(item.LimitedEditionStack);
            WriteInteger(item.LimitedEditionStack - item.LimitedEditionSells);
        }
    }
}

Would become something like this...

public void DoSomething() {
    WriteString(item.Data.Type.ToString());

    if (item.Data.Type.ToString().ToLower() == "b")
    {
        WriteString(item.Data.ItemName);
    }
    else
    {
        WriteInteger(item.Data.SpriteId);

        if (item.Data.InteractionType == InteractionType.WALLPAPER || item.Data.InteractionType == InteractionType.FLOOR || item.Data.InteractionType == InteractionType.LANDSCAPE)
        {
            WriteString(item.Name.Split('_')[2]);
        }
        else if (item.Data.InteractionType == InteractionType.BOT) //Bots
        {
            WriteString(!PlusEnvironment.GetGame().GetCatalog().TryGetBot(item.ItemId, out var catalogBot) ? "hd-180-7.ea-1406-62.ch-210-1321.hr-831-49.ca-1813-62.sh-295-1321.lg-285-92" : catalogBot.Figure);
        }
        else if (item.ExtraData != null)
        {
            WriteString(item.ExtraData ?? string.Empty);
        }

        WriteInteger(item.Amount);
        WriteBoolean(item.IsLimited);

        if (item.IsLimited)
        {
            WriteInteger(item.LimitedEditionStack);
            WriteInteger(item.LimitedEditionStack - item.LimitedEditionSells);
        }
    }
}

Upvotes: 0

Views: 433

Answers (2)

Paul
Paul

Reputation: 3306

I think this is what you want...

enter image description here

Upvotes: 1

Patrick Artner
Patrick Artner

Reputation: 51643

Cited from https://confluence.jetbrains.com/display/NETCOM/ReSharper+Customization+Guide#ReSharperCustomizationGuide-Language-specificFormattingStyles

go to Code Editing | [Language] | Formatting Style. Depending on the language there may be up to hundred different settings, which allow you to define every detail of your code layout. Formatting settings may be divided into several pages:

Braces Layout lists settings that determine how curly braces are laid out. This feature is only available for languages that use curly braces for scoping, such as C#. Blank Lines lists settings that determine how many blank lines are added in particular use instances. A value of 0 implies that no blank lines are used.

You look for the Blank Lines settings. Your "use" is probably blank lines before/after (conditional) blocks.

Upvotes: 1

Related Questions