Search code examples
c#resharperanonymous-typesstylecop

Format inline anonymous type with ReSharper to be compliant with StyleCop


I have the following code:

var newItems = items.Select(x => new { x.Id, x.Name });

ReSharper reformats this to:

var newItems = items.Select(x => new {x.Id, x.Name});

Which gives the StyleCop warnings SA1012 and SA1013 I have tried this solution but it doesn't seem to work for anonymous types.

What setting do I need to modify in ReSharper to ensure the reformatting is StyleCop compliant?


Solution

  • There is an option that determines expected behaviour:
    C# -> Formatting Style -> Spaces -> Within single-line initializer braces.

    Also, you probably need to suspend and restart Resharper or restart Visual Studio.