In my current project I am using a library that is delivered to me. The API in this library provide an interface that is a bit big! The interface requires my class to implement two events as follows:
#region INotifyPropertyChanged Members
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
#endregion
#region INotifyPropertyChanging Members
public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging;
These two events have no meaning in my class and I just have to implement them for the sake of the interface.
As I start to compile my code I see the Warning CS0067 that indicates that my events are not used anywhere, which is true.
As usual, I don't want my code gets spoiled with warnings en I would like to sort out ALL MY WARNINGS. So I came across some options:
- Ignoring this warnig throughout the project.
This is too much, I don't want to avoid the benefit of getting this nice warning that just highlighted my problem. But if I would like to do so I need to put the number 0067 in the project properties page in Build tab onder the Supress warnings - The less wide solution would be to ignore this warning only in that file and I could do this by putting the code just before my declaration:
#pragma warning disable 0067
and then restore it after my declaration using
#pragma warning restore 0067
- The last option I just found from MSDN which seems a neat solution is to tell the compiler that I am deliberately not supporting this event and even if it would be called at runtime that would be a mistake.
To do so I need to throw an exception as follows:
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged
{
add { throw new NotSupportedException(); }
remove { }
}
public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging
{
add { throw new NotSupportedException(); }
remove { }
}