2

I've got coding standards that are going to drive me nuts. I was wondering - is there is a way to switch between two different styles and have my code formatted for me? That way, I can code with my way, and check-in their way.

I am well aware that C# uses new line braces. However, the company I got hired on for uses same line braces. If I want to get paid, I will follow their coding standards for better or worse.

I'd like to check-out, format to new line braces, code, format to same line braces, and check-in again.

I could go to tools->options->text editor->c#->formatting myself and change all the boxes every time, but that is quite a hassle.

Christopher Pisz
  • 3,757
  • 4
  • 29
  • 65
  • maybe you could show us both examples, because without knowing we can't really help you – slow May 16 '18 at 14:41
  • 5
    If the rest of your team is using one style, and you are required to be in that style to commit to the repo, maybe you should just use that style. – maccettura May 16 '18 at 14:44
  • @slw Just same line brackets vs new line brackets. – Christopher Pisz May 16 '18 at 14:45
  • @maccettura The question is not "what should I or shouldn't I do?"...it is can I switch code formats somehow myself after checkout and before checkin, easily? – Christopher Pisz May 16 '18 at 14:47
  • @maccettura and slw, I am well aware. Can we stop debating what it should be and concentrate on the question? The company uses same line brackets, so if I want to get paid, I have to as well. I'd like to code with new line brackets and convert for them before I checkin – Christopher Pisz May 16 '18 at 14:48
  • @ChristopherPisz I don't even understand why they all use same line brackets... After you set the ending bracket "}" it automatically sets it to new line brackets??? Are they really moving it down for every single thing? Doesn't make any sense to me – slow May 16 '18 at 14:50
  • @slw no, they've imported settings to override that behavior as part of thier visual studio setup. So, of course, I could go to tools->options->text editor->c#->formatting myself and change all the boxes every time, but that is quite a hassle. – Christopher Pisz May 16 '18 at 14:51
  • About the only choice you have is convert CRLF to UNIX (or vice versa) during commit if using GIT. Other than that, working on working code that is tested, then committed another way is asking for trouble –  May 16 '18 at 14:57
  • There is no built-in method to do what you want. Either you must look for an extension, see if you could automate the changes yourself using the built-in macro support (if this is still present, been a long time I used this), or live with the problem. – Lasse V. Karlsen May 16 '18 at 15:00
  • For the record, `[]` <- Brackets, `()` <- Parentheses, `{}` <- Braces. Not even sure everyone in this discussion is talking about the same thing. – itsme86 May 16 '18 at 15:05
  • @itsme86 edited op. – Christopher Pisz May 16 '18 at 15:08

1 Answers1

1

Have you looked at Resharper? I do not use it, but am aware it has an option for refactoring braces. Linked below is a post where a user is tinkering with the same line/new line brace options. This may (or may not) lead you to what you're looking for:

resharper and braces

markaaronky
  • 1,231
  • 12
  • 29
  • 2
    Yes, I've been looking at it all morning. It seems to only support one format at a time though, rather than allowing a switch between two. Even the import/export settings file is only one file. – Christopher Pisz May 16 '18 at 15:20
  • 1
    I'd have to go to resharper->options->c#->formattingstyle-> braces layout and flip every box in this picture, then format, and save, which would be about as much hassle as changing the built in VS settings every time. Was hoping for something as easy a few clicks or hotkey presses, like I had in C++ with astyle. https://ibb.co/ny26RJ – Christopher Pisz May 16 '18 at 15:44