Idents and code formatting

The question is about code formatting, idents and code style.
What I struggling for is to create a good builder for trees (have a lot of in my domain). So, what I want to have is something like:

Root root =
                new RootBuilder()
                    .AddFolder("First folder")
                        .AddFolder("Embedded folder")
                            .AddItem("1").Done()
                            .AddItem("2").WithDescription("second item in embedded folder").Done()
                            .Done()
                        .Done()
                    .AddFolder("Second folder")
                        .AddItem("1").WithDescription("some item").Done()
                        .AddItem("2").Done()
                        .Done()
                    .Done();

I hope that it's more or less obvious what the builder is doing. I've attached the code behind to the post.
But my company use ReSharper auto-format very wildly, and what I have is:

Root root =
                new RootBuilder()
                    .AddFolder("First folder")
                    .AddFolder("Embedded folder")
                    .AddItem("1").Done()
                    .AddItem("2").WithDescription("second item in embedded folder").Done()
                    .Done()
                    .Done()
                    .AddFolder("Second folder")
                    .AddItem("1").WithDescription("some item").Done()
                    .AddItem("2").Done()
                    .Done()
                    .Done();

It's ugly and much less readable, so I even have to use some other approach constructing my trees.
So, the question is how to handle it? Is there any way to override standard formatting policy (not globaly, but only for those specific builder files)?
I my head it shoud look like in the RootBuilder class below, public methods of which are marked with either [StepIn] or [StepOut], that provides enough information for ReSharper to organize idents.

public class RootBuilder
    {
        private readonly List<Item> _items = new List<Item>();
        private readonly List<Folder> _folders = new List<Folder>();

        [StepIn]  
        public FolderBuilder<RootBuilder> AddFolder(string name)
        {
            return new FolderBuilder<RootBuilder>(HostFolder, name);
        }

        [StepIn]  
        public ItemBuilder<RootBuilder> AddItem(string name)
        {
            return new ItemBuilder<RootBuilder>(HostItem, name);
        }

        private RootBuilder HostItem(Item item)
        {
            _items.Add(item);
            return this;
        }

        private RootBuilder HostFolder(Folder folder)
        {
            _folders.Add(folder);
            return this;
        }

        [StepOut]  
        public Root Done()
        {
            return new Root(_folders, _items);
        }
    }



Attachment(s):
Program.cs.zip

Please sign in to leave a comment.