On a build server, I see some weird message. It doesn't say so, but I think it's from some software called 'fx cop'
Warning CS0067: The event 'SunGard.Adaptiv.AnalyticsEngine.UI.CommonControls.DisabledCommand.CanExecuteChanged' is never used
How can I silence this message? Without changing what my class does.
sealed class DisabledCommand : ICommand
{
public event EventHandler CanExecuteChanged;
I stumbled upon docs for System.Diagnostics.CodeAnalysis.SuppressMessageAttribute
which sounds useful, but there aren't any examples for my warning.
If you need to create an event that is never raised, you should make a noop event:
public EventHandler CanExecuteChanged {
add { }
remove { }
}
The compiler is complaining because a default ("field-like") event will create a hidden backing field to store the handlers. Since you never raise the event, that field just wastes memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With