Initialization of the object can be simplified

0

After updating the nuget (18) packages, I compiled my project and gave this error:

  

Initializing the object can be simplified

It points to these files in my code.

GridTextColumn dataLib = new GridTextColumn();

Here is the complete class

public class Control
    {
        SfDataGrid dataGrid = new SfDataGrid();
        DataService dataService = new DataService();
        public async void CriaDataGrid()
        {
            dataGrid.AutoGenerateColumns = false;

            GridTextColumn dataLib = new GridTextColumn();
            dataLib.MappingName = "DataLib";
            dataLib.HeaderText = "Data";
            dataLib.Width = 80;
            dataLib.TextAlignment = TextAlignment.Start;
            dataLib.CellTextSize = 9;

            GridTextColumn cliente = new GridTextColumn();
            cliente.MappingName = "Cliente";
            cliente.HeaderText = "Cliente";
            cliente.Width = 180;
            cliente.TextAlignment = TextAlignment.Start;
            cliente.CellTextSize = 9;

            GridTextColumn vendedor = new GridTextColumn();
            vendedor.MappingName = "Vendedor";
            vendedor.HeaderText = "Vendedor";
            vendedor.Width = 180;
            vendedor.TextAlignment = TextAlignment.Start;
            vendedor.CellTextSize = 9;

            GridTextColumn filial = new GridTextColumn();
            filial.MappingName = "Filial";
            filial.HeaderText = "Filial";
            filial.Width = 100;
            filial.TextAlignment = TextAlignment.Start;
            filial.CellTextSize = 9;

            dataGrid.Columns.Add(dataLib);
            dataGrid.Columns.Add(cliente);
            dataGrid.Columns.Add(vendedor);
            dataGrid.Columns.Add(filial);

            //dataGrid.AllowResizingColumn = true;
            dataGrid.ItemsSource = await dataService.GetLiberaAsync();
            dataGrid.SelectionMode = SelectionMode.Single;
            dataGrid.SelectionChanged += DataGrid_SelectionChanged;
        }
        void DataGrid_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
        {
            //DisplayAlert("Alert", "You have been alerted", "OK");
        }
    }

EDIT1

Version of VS2017

    
asked by anonymous 26.10.2017 / 00:23

1 answer

2

This is not an error, it's a warning that says initialization can be done in a more readable and organized way.

The tip is that you initialize objects like this:

GridTextColumn dataLib = new GridTextColumn
{
    MappingName = "DataLib",
    HeaderText = "Data",
    Width = 80,
    TextAlignment = TextAlignment.Start,
    CellTextSize = 9
};

In addition, you'll probably get a warning asking to use var on the left side of the assignment, since the type can be inferred.

    
26.10.2017 / 00:59