pamidur / aspect-injector

AOP framework for .NET (c#, vb, etc)
Apache License 2.0
745 stars 112 forks source link

Make hidden methods inline #67

Open mshami85 opened 6 years ago

mshami85 commented 6 years ago

Hi, I think it is making advice code inline with methods is very useful option. is there a chance to see so?

pamidur commented 6 years ago

Hi, do you mean MethodIplm - Inlining or something else?

Do you mind provide a code sample how you think it might work?

mshami85 commented 6 years ago

Yes just like MethodIplm , But unfortunately I use .net 4.0 which has no inlining, is it possible to make it?

mshami85 commented 6 years ago

for example instead of being like this

this.__a$_TraceAspect.YYY();
MessageBox.Show("Test");
this.__a$_TraceAspect.XXX();

the code must be like this

Console.Write("Starting....");
MessageBox.Show("Test");
Console.Write("Ended");
pamidur commented 6 years ago

Ok I got it. It will never be inlined explicitly. So you will always see those aspect methods calls in debugger for example. What you can do however, is to tell JIT try to aggressively inline when translating to native code by applying [MethodImpl] to your Advice Methods.

pamidur commented 6 years ago

Just want to add the reason why: Aspects has access to their class fileds, so they can share data. This means that making calls inline (in fact copying code to the target methods) means that we need to track and keep references to aspect class fields. Another reason - inline prevents aspect debugging.