.net阻止CA1009 - 将'myclass.mymethod'的第一个参数声明为名为'sender'的对象 [英] .net prevent CA1009 - declare the first parameter of 'myclass.mymethod' as an object named 'sender'

查看:142
本文介绍了.net阻止CA1009 - 将'myclass.mymethod'的第一个参数声明为名为'sender'的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。



我在.NET项目中使用此代码:

Hello.

I've this code in my .NET project:

public delegate void CtrlVisible(Boolean v);



在一个没有实现EventArgs的类中。

我用它这样:




inside of a class which doesn't implements EventArgs.
I use it in this way:

rs.ctrlVisible += new clsReportStatus.CtrlVisible(rs_ctrlVisible);





其中rs_ctrlVisible为:



where rs_ctrlVisible is:

public event CtrlVisible ctrlVisible;





我该如何解决这个问题呢?



谢谢。



我有什么尝试过:



尝试阅读有关事件驱动开发的MSFT文档。

将实例转换为对象,然后再将它们转换为布尔值。



How should I fix that problem?

Thanks.

What I have tried:

Tried reading MSFT documentation about event driven development.
Casting instances to object and then converting them to Boolean again.

推荐答案

事件是一种特殊的多播委托,只能在声明它们的类或结构中调用。 - MSDN。



这意味着可以用作事件的委托的签名必须与所有事件的签名相匹配:对象发送者和EventArgs派生类实例。

bool不合适:它与事件签名不匹配。



更改您的委托作为建议的错误消息。
"Events are a special kind of multicast delegate that can only be invoked from within the class or struct where they are declared." - MSDN.

What that means is that the signature of a delegate that can be used as an event must match that of all events: an object sender, and a EventArgs derived class instance.
A bool is not suitable: it doesn't match the event signature.

Change your delegate as the error message suggested.


这篇关于.net阻止CA1009 - 将'myclass.mymethod'的第一个参数声明为名为'sender'的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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