Source code of a method.

TheFlyingFiddle theflyingfiddle at gmail.com
Sat Oct 26 13:38:12 PDT 2013


On Saturday, 26 October 2013 at 19:04:09 UTC, Gary Willoughby 
wrote:
> On Saturday, 26 October 2013 at 16:36:35 UTC, TheFlyingFiddle 
> wrote:
>> Is there a way to extract the source code of a method at 
>> compiletime?
>
> Nope. What do you need to do?


I'm currently making an AOP framework. I use UDA's to handle 
logging, exception handling ect.

It looks something like this currently.

class Foo : IFoo
{
     @Log("bar.txt") @DLLException()
     void bar(...params...)
     {
       //dosomething
     }
}

unittest
{
    alias TypeTuple!(LogWrapper, DLLExeWrapper, ...) wrappers;

    //Normal foo
    auto fooProto = new Foo();

    //Wrapped foo having some nice extra functionallity for Foo.bar
    IFoo foo = new wrap!(Foo, IFoo, wrappers)(fooProto);
}

Currently the wrappped foo delegates to fooProto aswell as adding 
the functinallity specified by the UDA's. I basically wanted to 
remove the
delegation. And just put the source code in the newly created foo 
specialisation.


More information about the Digitalmars-d-learn mailing list