digitalmars.D.learn - Injecting code into methods based on UDA's
- TheFlyingFiddle (18/18) Oct 19 2013 void logMsg(string file, string msg)
- TheFlyingFiddle (1/1) Oct 19 2013 Sry accedentaly clicked send while writing..
- TheFlyingFiddle (35/35) Oct 19 2013 Is it possible to inject code into a method with UDA's?
- Jacob Carlborg (4/7) Oct 20 2013 It's only possible to inject code using a template or string mixin.
- TheFlyingFiddle (1/3) Oct 20 2013 Ah, too bad. Thanks for the answer.
- Dicebot (5/8) Oct 20 2013 Well, it is possible to do it if you use some kind of own
void logMsg(string file, string msg) { //Log the message to the file. } struct Log { string logFile; LogInfo toLog; } class Foo { void bar() { /* do something */ } Log("fooInfo.txt", LogInfo.methodCall | LogInfo.returnValue) void baz() { //Doess } }
Oct 19 2013
Sry accedentaly clicked send while writing..
Oct 19 2013
Is it possible to inject code into a method with UDA's? For example if i wanted a method to do some logging when it's called. Something like the following. void logMsg(string file, string msg) { //Log the message to the file. } struct Log { string logFile; } class Foo { void bar() { /* do something */ } Log("fooInfo.txt") int baz() { //Does some calculation and returns some value. } } would expand the class Foo to (at compile time) class Foo { void bar() { } //unchanged int baz() { logMsg("fooInfo.txt", "Method Foo.baz was called."); //Let baz do it's thing } } I know that this can be done by using a wrapper template that creates a subclass but it would be nice if the code could just be injected with the UDA's somehow.
Oct 19 2013
On 2013-10-20 01:16, TheFlyingFiddle wrote:Is it possible to inject code into a method with UDA's? For example if i wanted a method to do some logging when it's called.It's only possible to inject code using a template or string mixin. -- /Jacob Carlborg
Oct 20 2013
It's only possible to inject code using a template or string mixin.Ah, too bad. Thanks for the answer.
Oct 20 2013
On Sunday, 20 October 2013 at 11:58:41 UTC, TheFlyingFiddle wrote:Well, it is possible to do it if you use some kind of own framework for declarative stuff and call the function only from it (thus implementing check of attached UDA's inside of the framework). Actual function modification is not possible.It's only possible to inject code using a template or string mixin.Ah, too bad. Thanks for the answer.
Oct 20 2013