I got around to some cleaning today removing all our project warnings, yes you know which I mean, those nasty yellow things in the bottom of your Visual Studio screen every time you build. The ones we shrug at and say “well, they’re just warnings” 🙂
I got most of them since they were really easy issues but at one point I actually wanted the “fault” to be implemented that way. We had a design-time view model implementing the base interface which had an INotifyPropertyChanged interface (I could possibly have moved this interface down a level to not get it on the design time view model but in some situations that might not be feasible). So, it would look something like this:
Warning 7 The event '....DesignTimeCreateProjectViewModel.PropertyChanged' is never used ...DesignTimeDesignTimeCreateProjectViewModel.cs 19 50
The code line generated that generated this was the following
public event PropertyChangedEventHandler PropertyChanged;
As I mentioned, since I wanted/needed to implement this this interface I couldn’t just comment out the line and I don’t fancy putting in code to invoke it just to be rid of a warning. So, instead, if you have a look at the output view the build will give you this version of the warning:
......ViewModel.cs(31,66,31,74): warning CS0067: The event '....PropertyChanged' is never used
The important bit here is the warning error code, in this case CS0067, removing the CS-bit we can use this with a preprocessor directive to temporarily remove this exclude this warning when compiling this bit of code, the end result:
#pragma warning disable 0067 // No "Never used" warning public event PropertyChangedEventHandler PropertyChanged; #pragma warning restore 0067
And our warning is gone! I’m not a fan of these cluttering preprocessors but since this is something that will never be used and can be hidden in the design time class without risk I find it a neat alternative to changing your implementation or adding stuff that won’t be used.
Since you need to end with a proverb or catchphrase I’ll use one that annoyed my senior the other day 🙂
There is no problem without a solution, you just have to find it!
yeah, well, thanks a lot 🙂