aspects on methods?

jj75607 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 12 04:26:20 PDT 2016


I want to use aspect-like annotations to transform

   @Lockable
   class Abc
   {
       @sync
       void f() {
           writeln("f");
       }

       @shared
       void g() {
           writeln("g");
       }
   }

to something like:

   class Abc
   {
       shared(ReadWriteMutex) _lock123;

       this()
       {
           _lock123 = cast(shared)(new ReadWriteMutex());
       }

       void f() {
           synchronized((cast()_lock123).writer) {
               writeln("f");
           }
       }

       void g() {
           synchronized((cast()_lock123).reader) {
               writeln("g");
           }
       }
   }

How can I do that?


More information about the Digitalmars-d-learn mailing list