I have a class with some abstract methods, but I want to be able to edit a subclass of that class in the designer. However, the designer can’t edit the subclass unless it can create an instance of the parent class. So my plan is to replace the abstract methods with stubs and mark them as virtual – but then if I make another subclass, I won’t get a compile-time error if I forget to implement them.
Is there a way to mark the methods so that they have to be implemented by subclasses, without marking them as abstract?
Well you could do some really messy code involving
#if– i.e. inDEBUGit is virtual (for the designer), but inRELEASEit is abstract. A real pain to maintain, though.But other than that: basically, no. If you want designer support it can’t be abstract, so you are left with ‘virtual’ (presumably with the base method throwing a
NotImplementedException).Of course, your unit tests will check that the methods have been implemented, yes? ;-p
Actually, it would probably be quite easy to test via generics – i.e. have a generic test method of the form: