0

Code formatting - help needed

This is how Visual Studio 2012 currently formats my code. This is formatting is applied if paste new code in, or if I explicitly choose to format the document using VS shortcut Ctrl K,D.

    private static void MyFunc()
    {
        var ints = new List<int>();
        var diffInts = ints.Select(x => new
        {
            Prop1 = x,
            Prop2 = x * x
        })
                           .ToList();

        diffInts.ForEach(x =>
        {
            if (x.Prop2 > x.Prop1)
            {
                Console.WriteLine("Whatever!");
            }
        });
    }

However I have configured R# (7.1.latest) to format the code as below

    private static void MyFunc()
    {
        var ints = new List<int>();
        var diffInts = ints.Select(x => new
                                        {
                                            Prop1 = x,
                                            Prop2 = x*x
                                        })
                           .ToList();

        diffInts.ForEach(x =>
                         {
                             if (x.Prop2 > x.Prop1)
                             {
                                 Console.WriteLine("Whatever!");
                             }
                         });
    }

R# kicks in its formatting only if I terminate a statement (ie using `;`) or if I terminate a block (ie using `}`). Otherwise I need to explicitly format the document using the R# shortcut Ctrl+Atl F.

This is quite tedious as I frequently move code around, the code looses all formatting (ie resets to VS style formatting).

What can I do to get rid of this annoyance? I presume I will need to share some R# settings values as well as some VS settings values. Please let me know which ones (and if possible, in which sub section I can find those settings)

6 comments

Please sign in to leave a comment.