简体   繁体   中英

Disable IDE2018 in VS2017

Just updated to VS2017 from VS2010, (Whence went simplicity?)

Does anyone know how to "easily" disable IDE0028?

I am getting an IDE0028 (Collection initialization can be simplified) message when I do this...

        List<string> colNames = new List<string>();
        colNames.Add("Desc");
        colNames.Add("Freq");
        colNames.Add("Date");
        colNames.Add("Amount");
        colNames.Add("Pay From");
        dgv_SetHeaderNames(dgvDebits, colNames);
        dgvDebits.ColumnCount = colNames.Count;
        colNames[4] = "Type";
        dgv_SetHeaderNames(dgvIncome, colNames);
        dgvIncome.ColumnCount = colNames.Count;

        colNames.Clear();
        colNames.Add("Key");
        colNames.Add("Description");
        colNames.Add("Date");
        colNames.Add("Freq");
        colNames.Add("Amount");
        colNames.Add("Pay From");
        colNames.Add("USAA Checking");
        colNames.Add("Amazon VISA");
        dgv_SetHeaderNames(dgvWorking, colNames);

As you can see I reuse the colNames list for more than one DataGridView.

Personally, I think it is clearer the way I am doing it because it clearly delineates item ans a separate item in a list. So, I don;t like IDE0028

For the curious the called function is here:

    public void dgv_SetHeaderNames(DataGridView dgv, List<string> colNames, bool withColNum = false)
    {
        foreach (DataGridViewColumn dgvCol in dgv.Columns)
        {
            int currCol = dgvCol.Index;
            string colText = "";
            if (currCol >= colNames.Count)
            {
                // if there are more columns than name we will use the column number, anyway.
                colText = currCol.ToString();
            }
            else
            {
                if (withColNum == true)
                {
                    colText = currCol.ToString() + " - " + colNames[currCol];
                }
                else
                {
                    colText = colNames[currCol];
                }
            }
            dgv.Columns[currCol].HeaderText = colText;
        }
    }

Yes, I am still a newbie, and will probably be one for some time to come...

OK, a bit of asking Google the same question many ways...

In Solution Explorer Right-Click

Expand: Microsoft.CodeAnalysis.CSharp.Features use with Caution and remember what you've changed...

Not sure at this point if this is a global or a per project change...

[EDIT] I had asked another question and got an answer giving me a bit of information I did not know. Specifically, that if you click the light bulbs down arrow you will get a correcting "Suggestion".

In my case I do not lose the list structure...

This...

    List<string> colNames = new List<string>();
    colNames.Add("Desc");
    colNames.Add("Freq");
    colNames.Add("Date");
    colNames.Add("Amount");
    colNames.Add("Pay From");

Becomes This...

    List<string> colNames = new List<string>
    {
        "Desc",
        "Freq",
        "Date",
        "Amount",
        "Pay From"
    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM