Reporter | Angelina Elycheva (Angelina.Elycheva) |
---|---|
Created | Jun 2, 2015 3:38:44 PM |
Updated | Apr 23, 2018 12:57:14 PM |
Subsystem | Code Style - Formatter |
Assignee | Dmitry Osinovsky (Dmitry.Osinovsky) |
Priority | Normal |
State | Submitted |
Type | Feature |
Fix version | Backlog |
Affected versions | No Affected versions |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
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:
But my company use ReSharper auto-format very wildly, and what I have is:
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.
Root root =I hope that it's more or less obvious what the builder is doing. I've attached the code behind to the post.
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();
But my company use ReSharper auto-format very wildly, and what I have is:
Root root =It's ugly and much less readable, so I even have to use some other approach constructing my trees.
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();
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);
}
}