简体   繁体   English

在 VS2017 中禁用 IDE2018

[英]Disable IDE2018 in VS2017

Just updated to VS2017 from VS2010, (Whence went simplicity?)刚刚从 VS2010 更新到 VS2017,(哪来的简单?)

Does anyone know how to "easily" disable IDE0028?有谁知道如何“轻松”禁用 IDE0028?

I am getting an IDE0028 (Collection initialization can be simplified) message when I do this...执行此操作时,我收到 IDE0028(可以简化集合初始化)消息...

        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.如您所见,我为多个 DataGridView 重用了 colNames 列表。

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所以,我不喜欢 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...展开:Microsoft.CodeAnalysis.CSharp.Features 谨慎使用并记住您所做的更改...

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"
    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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