formattingvisual-studio-2013resharper-8.1

Weird formatting of properties in Resharper 8


I have a problem with Resharper 8.
Everytime I declare a property in my code, Resharper completely ruins my code:

class MyClass
{
    public int MyProp { get; set; }
}

will be reformatted to:

class MyClass
{
    public int MyProp { get; set; }
}
}

And if I declare "small" properties like:

class MyClass
{
    public int MyProp { get { return 1; } }
}

it will be reformatted to:

class MyClass
{
    public int MyProp
    {
        get { return 1; }
    }
}

Is there a way to fix the first case and is there a way to tell Resharper how long a single-lined property is allowed to be?
If I have very short properties I don't want them to spread over multiple lines.

If it is not fixable how can I tell Resharper to use Visual Studio's formatting in that cases?


Solution

  • To make sure 'short' properties get formatted on the same line,

    go to ReSharper -> options -> Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping

    and on the right-pane , scroll all the way down to 'Other',

    then tick the 'Place Simple property/indexer/event declaration on single line' option.

    You would see the preview window changing from

    class C
    {
        private int Property
        {
            get { return x; }
            set { x = value; }
        }
    }
    

    to

    class C
    {
        private int Property { get { return x; } set { x = value; } }
    }