[VB]代码样式建议删除事件处理程序的未使用参数 [英] [VB]Code Style Suggests Remove Unused Parameter for Event Handlers

查看:96
本文介绍了[VB]代码样式建议删除事件处理程序的未使用参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Visual Studio 2019社区。在"错误列表"窗口中,它列出了删除未使用参数的选项,例如:

I am currently using Visual Studio 2019 Community. In the Error List window, it lists the option to remove unused parameters, such as the following:

正如您可能猜到的,这些参数中的大多数(发送者和发送者)来自事件处理程序。如果我删除它们然后处理程序将不符合要求(我会认为VS会知道)。即使收到未使用的
参数的通知会很好,但几乎所有的事件处理程序都看到这些参数非常令人沮丧,所以我去了Code Style(工具 - >选项 - >文本编辑器 - >基本 - >代码样式)并尝试更改"避免未使用的参数"选项。但是,这个
似乎没有帮助。我认为Visual Studio&代码样式足够聪明,可以忽略处理程序所需的未使用参数,但无论如何,有没有办法对此做任何事情,或者我是否需要在配置或项目文件中手动禁用IDE0060
?谢谢。

As you can probably guess, most of these parameters (sender & e) are from event handlers. If I removed them then the handlers would not meet the requirements (and I would think VS would know that). Even though it would be nice to be notified of unused parameters, seeing these for almost all of my event handlers is very frustrating, so I went to Code Style (Tools -> Options -> Text Editor -> Basic -> Code Style) and tried to change the "Avoid unused parameters" option. However, this did not seem to help. I would think that Visual Studio & Code Style would be smart enough to ignore unused parameters that are required for the handlers, but either way, is there a way to do anything about this, or do I need to manually disable IDE0060 in a configuration or project file? Thanks.

Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

推荐答案

嗨Nathan Sokalski,

欢迎来到MSDN论坛。

老实说,我们知道这对你来说是多么令人沮丧,但我们无法在我身边重现它。如果可能的话,您是否可以在此方便地提供演示,以方便诊断。
 

如果可能,您可以检查以下方法是否有用:

第一种方法:

the first method:

#define UNUSED(x)(void)x

Void SomeFunction(int param1,int param2)

{

   UNUSED(param2);

   //用param1做东西

}

UNUSED(param2)语句不生成任何对象代码,消除了对未使用变量的警告,并澄清文件,而不是变量的代码。

第二种方法:

The second method:

警告:未使用的参数'mcb'

  示例:

         Int ifnMenuQuit(MCB_T * mcb)

        ;      {

          ;    返回QUIT;

         ;     }

  说明:因为函数中没有使用函数参数中的mcb,所以警告

  修改:对未使用的参数使用para = para;

     ;       Int ifnMenuQuit(MCB_T * mcb)

        ;      {

          ;&NBSP;&NBSP;&NBSP;&NBSP; MCB = MCB; < ----------添加此行

    ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;返回QUIT;

         ;&NBSP;&NBSP;&NBSP;&NBSP; }

期待你的回复

Best

可能


这篇关于[VB]代码样式建议删除事件处理程序的未使用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆