Description
Metaprogramming is our holy grail. It comes up time and time again. Combined with the Code-injectors compiler feature I think the ability to replace members could get us most of the benefit. Even though in C# we've been working under the assumption that you'll just have a member modifier replace
I'm considering something broader in VB. These modifiers parallel what we can do today with inheritance but instead work across partial class definitions.
Replaceable
Opts a member into being replaced. Replacement isn't required. Maybe we might need a way to specify this at the class level?
Replaces
Specifies that the decorated member implementation will replace a matching replaceable definition elsewhere.
MustReplace
Creates a member stub which code can bind to but whose implementation must be provided elsewhere. This is almost exactly like a Partial but it can apply to more member types and have any accessibility.
NotReplaceable
Specifies that the decorated member may not be replaced. Attempting to do so results in an error.
And, of course, we'd need some kind of MyOriginal
keyword to call into the original implementation.
There are more moving parts than what we've considered in C# but they come in handy when thinking about how multiple code-injectors would compose with each other.
The big scenarios I'm interested in with a feature like this is somehow making INotifyPropertyChanged
implementations less tedious and MVVM much more approachable. But I believe this feature would also allow us to create more abstractions without having to modify the language itself so much. For example, if we allow a field to be replaced with a property we could implement (convention based) Handles without the WithEvents modifier/special code gen. There might also be some stuff in My we could do better. Need a prototype to see how far we can go.
Some open questions
- Should you have to opt-in to being replaceable?
- Should we allow a single member to be replaced more than once?