Tools for building a dynamic derived type? I need a push in the right direction.

Jacob Carlborg doob at me.com
Tue Aug 20 23:49:54 PDT 2013


On 2013-08-20 20:55, Gary Willoughby wrote:

> The general usage is probably going to be something like this:
>
> class Mock(T) : T
> {
>      // Implementation
> }
>
> auto cat = Mock!Cat("Ginger"); // constructors supported.
>
> auto person = Mock!Person();
>
> person.addMethod("getName", delegate(){
>      return "Foo";
> });
>
> person.addMethod("getAge", delegate(){
>      return 10;
> });
>
> Any help will be greatly appreciated.

I'm not exactly sure how you want it to work, but this is an idea:

Create and store an instance of T in Mock. Implement opDispatch in Mock 
and forward an methods added by addMethod to the delegate. If no 
delegate exists for that method forward to the instance of T instead.

http://dlang.org/operatoroverloading.html#Dispatch

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list