Shadow a sealed class

Moved the discussion from Experimenting with mapped types to a new topic.

I ended there with the statement that I want to try to convert my VB shadow class functionality to Oxygene.

But the VB Version writes code - no aspects, as there are no aspects in VB.
And the longer I ink about it, the more I get convinced that it won’t work with an aspect.

The code:

[Shadows(MySealedClass)]
type MyClass = public Class
public method ReimplementedMethod;
end;

Without the aspect expanding the code, the only method on MyClass will be ReimplementedMethod, as it inherits from Object - the editor can not see that the functionality of the MySealedClass is also supported by MyClass, because the aspect is only generating the needed code for that at compile time.

@ck, @mh, Do I see this right?

I would expect so, yes. I don’t believe Aspects run for CC. But Carlo will know for sure.

A full case.

type c1 = public sealed class
  public method Method1;
  public method Method2;
end;

[Shadows(MySealedClass)]
type c2 = public class
  public Method Method1; 
  begin
    // reimplements Method1
  end;
end;

This will generate the following code (replacing the class c2):

type shadow_c1 = public class //will also implement all interfaces of c1
  [ExposeEvents]private var fBase: c1;
  public property Base: c1 Read fBase; virtual;
  public constructor(base: 
  //map all public constructors, methods, properties, fields, delegates, events and interfaces
  public method Method1;
  begin
    fBase.Method1;
  end;
  public method Method2;
  begin
    fBase.Method2;
  end;
  //operators added
  operator Implict(aOther: c1): shadow_c1 ;
  begin
    exit fBase;
  end;
  operator Explicit(aOther: c1): shadow_c1 ;
  begin
    exit fBase;
  end; 
end;

type c2 = public class(shadow_c1)
  public Method Method1; reintroduce;
  begin
    // reimplements Method1
  end;
end;

Right; aspects don’t trigger at code completion (this would massively slow down the compiler if it did). Btw a simpler way to solve the original problem (call a different SubString implementation) is to use a MethodCallAspect;

[MethodAspectAttribute(typeOf(RemObjects.Elements.String), false, 'Substring', 0, [typeOf(Int32), typeOf(Int32)])]
[MethodAspectAttribute(typeOf(RemObjects.Elements.String), false, 'Substring', 0, [typeOf(Int32)])]
SubstringAspect = public class(IMethodCallDecorator)
public
  method ProcessMethodCall(aContext: IContext; aMethod: IMethod; aValue: ParameterizedValue): Value;
  begin
  end;
end;

this will trigger ProcessMethodCalll (which has to return a new value to the new call)

So an aspect can override an existing method?
That would solve everything for me.

Not exactly. It can override calls to a method and do something else. Effectively this will end up doing the same thing for you.