5

When I use Resharper to refactor my code to use an Object initializer, it reformats the code correctly as thus, the following code

var response = new Response(); 
response.Value = "My value";

becomes

var response = new Response
{
   Value = "My value",
};

I can't find anyplace in Resharper options where I can set it up to retain the parentheses as part of the constructor code (which I prefer for consistency). Is it possible? I would like Resharper to format it thus:

var response = new Response()
{
   Value = "My value",
};
Patrick Szalapski
  • 8,738
  • 11
  • 67
  • 129
  • 1
    If this does not exist, this would be a feature request for the product. – gunr2171 Jul 24 '14 at 16:09
  • 1
    R# treats these parentheses as redundant (because they really are). I guess disabling the redundant parentheses inspection might help? – Federico Berasategui Jul 24 '14 at 16:13
  • given they *are* redundant, why do you want to keep them? – Peter Ritchie Jul 24 '14 at 16:15
  • @PeterRitchie He already explained that.. "which I prefer for consistency" – User 12345678 Jul 24 '14 at 16:24
  • 2
    "Consistency" with what? These are object initializers, they are different from just constructor invocation--there is no inherent "consistency". If anything, including the "()" is "inconsistent" because they are initializers and not just constructor invocations. – Peter Ritchie Jul 24 '14 at 16:29
  • 1
    Consistency with ordinary constructors. Initializers are not different from constructor invocation in that the constructor is still called; I think it would be bad practice to be inconsistent with the syntax, as code exists first to be read by humans and only incidentally for computers to execute. – Patrick Szalapski Jul 24 '14 at 17:27
  • 1
    @HighCore, I tried disabling "Remove redundant parentheses" in Context Actions, but I think this just omits it as a context choice. In any case, this didn't affect the behavior I noted. Anywhere else I can look? – Patrick Szalapski Jul 24 '14 at 17:43

1 Answers1

0

Sounds like this feature is not available in Resharper.

Patrick Szalapski
  • 8,738
  • 11
  • 67
  • 129