Overriding implementation class members
On the way home I thought of a way to override implementation class members in the user class.
class User use SomeImpl for IFooBar [OverrideImpl(IFooBar)] private SomeMethod() : void // specialized code... class SomeImpl : IFooBar public virtual SomeMethod() : void // Normal code
The macro can translate this into “real” code by creating a new class inside User that inherits from the implementation class. We override the virtual method and make call to the User method.
The partial expansion then looks like this:
class User use SomeImpl_User_Overrides for IFooBar private SomeMethod() : void // Specialized code class SomeImpl_User_Overrides : SomeImpl private _user : User public this(user : User) _user = user public override SomeMethod() _user.SomeMethod()
So then we use the specialized class as the implementation.
This approach will also work for abstract methods defined in the implementation class that require implementation.