简体   繁体   English

CS0067 on C# 接口事件实现

[英]CS0067 on C# Interface Event Implementation

I have an interface in C# with some events.我在 C# 中有一个带有一些事件的接口。

Thus, the code using it is using only the interface, never the implementation.因此,使用它的代码只使用接口,而不是实现。

Then the events are triggered by a base class.然后事件由基础 class 触发。 So neither the class consumer nor the implementation directly refers to the event.所以 class 消费者和实现都没有直接引用事件。 It's defined in the base class and in the interface.它在基础 class 和接口中定义。

As a result, I get CS0067 warning that the implementation events are never used.结果,我收到 CS0067 警告说从未使用过实现事件。

What's the best way to deal with that?处理它的最佳方法是什么?

It looks like a similar question here (Check this)这里看起来像一个类似的问题(检查这个)

This warning 67 can be suppressed with:可以通过以下方式抑制此警告 67:

#pragma warning disable 67

If you are forced to implement an event from an interface, that your implementation doesn't need you can do the following to avoid the warning.如果您被迫从接口实现事件,那么您的实现不需要您可以执行以下操作以避免警告。

public event EventHandler CanExecuteChanged { add{} remove{} }

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

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