Is it possible to reverse a RS code suggestion?

I took RS' advice about converting class assignments to object initialisers a bit too liberally. Having refactored my code I've now come to the conclusion that this trivial example:

columnHeader = new ColumnHeader {Name = columnName[8], Text = columnText[12]};

Is a bit easier on the eye if I have this instead:

ColumnHeader columnHeader = new ColumnHeader();
columnHeader.Name = columnName[8];
columnHeader.Text = columnText[12];

What I've described is basic but I've got a lot of code I've changed that have many properties so manually editing is a bit cumbersome. No big deal I know. That got me thinking that if RS can make a suggestion to change something it would be nice to have an "anti-suggestion" to reverse it. :)

I can't undo the changes but it could be useful in some situations. Does RS have some magical keystroke sequence already embedded that I could use to convert the code back to the way I used to have it?

I'm now using "// ReSharper disable UseObjectOrCollectionInitializer" comments to disable the suggestion on the more lengthy conversions.

Comment actions Permalink


AFAIK, there is no way to reverse the code changes once you have closed the document (otherwise just Undo it).

However, if your concern is about readability, I suggest you to make the following change: open ReSharper options, go to C# > Formatting Style > Line Breaks and Wrapping, and change "Wrap object and collection initializer" to "Chop always".

This way, your initializer will always look like this:
ColumnHeader columnHeader = new ColumnHeader {
Name = columnName[8],
Text = columnName[12]
which is, IMHO, the easiest on the eye you can find.


Comment actions Permalink

Works for me! Thanks.


Please sign in to leave a comment.