Automatically formatting lambda functions in Visual Studio 2010

How to configure Visual Studio 2010 so that multi-line lambda functions do not look ugly, with all this empty space to the left?

dataView.CellFormatting += (s, e) => { if ((e.ColumnIndex == 1)&&((dataView.SelectedCells.Count == 1))) { var scope = Scope.Instance; var row = dataView.Rows[e.RowIndex]; var variable = row.DataBoundItem as Variable; if (scope.Variables.Contains(variable)) { dataView[e.ColumnIndex, e.RowIndex].Style.BackColor = scope.GetGraph(variable).Color; } else { dataView[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White; } } }; 
+6
source share
2 answers

It depends on how much white space you find ugly, but one thing you can do to minimize it is getting into the carriage by returning immediately after being equal. Then you will get something like this. `

  { var raw_custs = (from customer in GetActive() where customer.Name.Contains(name) select customer).Take(numberToGet).ToList(); 

I usually press CTRl-E CTRL-D immediately after making such a change so that the document is automatically formatted (Edit-> Advanced-> Format Document)

(Just saw your corrected post - when I put this in VS and typed return after + =

 dataView.CellFormatting += (s, e) => { if ((e.ColumnIndex == 1) && ((dataView.SelectedCells.Count == 1))) { var scope = Scope.Instance; var row = dataView.Rows[e.RowIndex]; var variable = row.DataBoundItem as Variable; if (scope.Variables.Contains(variable)) { dataView[e.ColumnIndex, e.RowIndex].Style.BackColor = scope.GetGraph(variable).Color; } else { dataView[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White; } } 
+2
source

Now that it's odd, indents shouldn't go that far.

Try to cut and paste it into place, and Visual Studio will fix it to paste. This is what I get:

 dataView.CellFormatting += (s, e) => { if ((e.ColumnIndex == 1) && ((dataView.SelectedCells.Count == 1))) { var scope = Scope.Instance; var row = dataView.Rows[e.RowIndex]; var variable = row.DataBoundItem as Variable; if (scope.Variables.Contains(variable)) { dataView[e.ColumnIndex, e.RowIndex].Style.BackColor = scope.GetGraph(variable).Color; } else { dataView[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White; } } }; 
+1
source

Source: https://habr.com/ru/post/902085/


All Articles