Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resharper inline object initialisation

Tags:

c#

resharper

I work with resharper and when I clean my code I get this layout:

mock.Setup(m => m.Products).Returns(new List<Product>{new Product{Name = "Football", Price =    25}, new Product{Name = "Surf board", Price = 179}, new Product{Name = "Running Shoes", Price = 95}}.AsQueryable());

I'd rather have:

mock.Setup(m => m.Products).Returns(new List<Product>{
    new Product{Name = "Football", Price = 25}, 
    new Product{Name = "Surf board", Price = 179}, 
    new Product{Name = "Running Shoes", Price = 95}
}.AsQueryable());

is this possible?

like image 389
Patrick Avatar asked Feb 23 '12 11:02

Patrick


People also ask

How do I inline a method in ReSharper?

Choose ReSharper | Refactor | Inline | Inline… in the main menu. The Inline Method dialog will open. If you have invoked the refactoring at a method usage, you can clear the Inline all usages checkbox to inline only the current usage.

What is ReSharper?

ReSharper provides both a quick-fix and a context action to transform assignment statements into C# object initializers, and both are called ReSharper provides both a quick-fix and a context action to transform assignment statements into C# object initializers, and both are called Product Blogs IDEs AppCode CLion DataGrip DataSpell Fleet GoLand

What is the use of object initializer in Java?

Besides, initializers are useful in multi-threading. Object initializers are used to assign values to an object’s properties or fields at creation time without invoking the constructor. If you create an object and then right after that assign values to its properties, ReSharper suggests using an object initializer.

When should I use a collection initializer?

Collection initializers can be used if a collection class implements IEnumerable or has an Add method. If you create a collection and then immediately populate it with items, ReSharper suggests using a collection initializer. In the following, ReSharper replaces invocations of the Add method with a collection initializer:


1 Answers

You should be able to do what you want by using the Resharper Options (Main Menu -> Resharper -> Options).

There are two places you need to look:

Braces Layout > Array and Object InitializerLayout

And here:

Line Breaks and Wrapping > Object and Collection Initializers

like image 115
dash Avatar answered Oct 17 '22 04:10

dash