Here is a simple example of a one-lined IF statement.
if(condition)
something = "blah";
I find myself using them often for simple things, but later on while expanding the application, expanding them to a multi-lined if statements
if(condition)
{
something = "blah;
somethingElse = "blar";
}
But I find this quite frustrating because I have to go through several steps to do so. When I enter the first brace, my code formatter (Visual Studio? Resharper?) proceeds to enter a second (closing) brace, and formats it like so:
if(condition) { }
something = "blah";
I then have to select and remove the closing brace, and do my own formatting to get it to look correct.
Is there a way that I can conveniently have resharper or visual studio automatically enter the braces around the one-lined IF statement? e.g: I entered an opening brace after the condition and it automatically formatted it like
if(condition)
{
something = "blah";
}
What you can do is define a new snippet that is exactly like the if code snippet without the "if ($expression)" part:
Then you can import this snippet into visual studio by:
or: Copy your new snippet file into C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#
You can then select the body of your single line if statement in your c# file, right click and select Surround With... then select your new snippet.