In .NET, can a base class somehow ensure derived classes define shared members?

When I inherit from a base class, Visual Studio (v2008 here) informs me about all MustInherit members that need to be created in the derived class, which is very handy.

However, I also want my derived class to define some shared members - the values of which will be different for each derived class. Unfortunately, .NET doesn't allow MustInherit on shared members in a base class.

Is there any other way of getting Visual Studio to remind me that my derived class should also include certain specific shared members?

Jon Skeet
people
quotationmark

No, there's no way of doing this - and it sounds like a design smell, to be honest.

Half the point of having MustInherit members is that you can then access them from the code in the base class. That wouldn't be appropriate for Shared members, as there'd be no indication of which class to access the shared members of.

You haven't given us any context to explain why you want to do this, but I suggest you try to look for a different design. Sometimes having parallel inheritance hierarchies (e.g. one for "factories" and one for instances) can be useful, for example - then the members you might otherwise make Shared would be instance members within the factory types. It really does depend on what you're trying to achieve though.

people

See more on this question at Stackoverflow