For example, I get this compiler warning,
The event \'Company.SomeControl.SearchClick\' is never used.
But I know that it\'s use
The second best way is imho to clearly state that the event is not supported by throwing an exception if someone tries to subscribe to it.
public event RoutedEventHandler SearchClick
{
add { throw new NotSupportedException(); }
remove { throw new NotSupportedException(); }
}
As a variant on this, you can also just leave the add
and remove
methods empty to silently ignore subscriptions on the event.
The best solution is to refactor the code, perhaps pull the declaration of the event to the implementor if possible.
As a last resort, you can also disable the warning like so
#pragma warning disable 67
public event RoutedEventHandler SearchClick;
#pragma warning restore 67