I have a series of classes that have a number of analogous Shared
methods that I want to ensure are implemented in a consistent manner in each class. These Shared
methods are called via reflection in various areas of code, and up to this point I’ve been keeping them in synch manually. As the number of classes grows, ensuring synchronization is becoming a bit tedious – as is the process to ensure, when I add a new Shared
method to the paradigm, that it is indeed implemented in all of the classes to prevent run-time errors when reflection comes looking for them.
I’d initially thought this would be an ideal use of interfaces, but per various threads (such as Why we can not have Shared(static) function/methods in an interface/abstract class?) you cannot define Shared
methods as part of an interface. I then tried to define a common base class and mark these methods MustOverride
, but you cannot do that either. I’ve looked into delegates (which I’ve not used before), but it appears to allow the opposite of what I’m trying to do (namely, delegates seem to allow a common implementation of a common need from multiple classes instead of a unique implementation of a common need from multiple classes).
As such, is there an approach in VB.Net to ensure at compile-time that each of my classes implements a set of common Shared methods and functions in a consistent manner?
As a side note, the classes in question are currently all extensions of Entity Framework classes and are being blended into the EF classes.
EDIT: As a alternative to a language feature (which may not exist), I'd also be open to suggestions on any refactoring-type tools that provide this sort of functionality.