How to force a compile error when virtual method hiding of base class occurs?
.net, c#, compiler-warnings, overriding, visual-studio-2013
Solution
You can change your project properties to treat a specific warning as error.
Go to Project Properties -> Build
There Check Specific warnings: under "Treat warnings as erros' and specify:0114 as warning number.
Now this particular warning will appear as error. This could be helpful but it mainly depends on the developers, if they choose to ignore the warning in first place then they can accidentally remove this warning number from build properties as well.
For your question:
does VS 2015 or C#6 add anything which helps in this issue?
You will get the same behaviour/warning in Visual Studio 2015, for C# 6.0. It is same as previous version.
Problem
I have a virtual method in a base class which has a full implementation. A developer deriving from this class might mistakenly create a method with the same name without overriding the base class (not knowing there's a proper base class method to be used). The compiler gives a warning that the new method is hiding the base method. The problem is compiler warnings are easily ignored or not noticed. Is there a way to give a compiler error instead.. or some kind at your face warning? I want developers to consciously override the base method if they want to use their own implementation and not just create one with same name. I can't force other developers' Visual Studio to set warnings as errors. Plus there are already existing warnings which no one is going to fix. Side question: If current VS2013 and C#5 has nothing to address this, does VS 2015 or C#6 add anything which helps in this issue?