Download Postsharp (Visual Studio Gallery).
Install an AOP compiler and introduce postsharp.aspects (note the free Express version during installation), and then the initial demo code:
usingpostsharp.aspects;usingSystem;namespaceconsoleapplication1{[Serializable] Public classAopiltestattribute:onmethodboundaryaspect { Public Override voidonentry (Methodexecutionargs args) {Console.WriteLine ("Entry Method:"+args. Method.name); varArgumentList =args. Arguments; vararguments =args. Method.getparameters (); for(inti =0; I <arguments. Length; i++) {Console.WriteLine ("parameter name:"+ Arguments[i]. Name +"\ t parameter type:"+ Arguments[i]. ParameterType +"\ t parameter value:"+Argumentlist[i]); } } } Public classMaintest { Public Eventaction<int> myaction =NULL; Public voidCall () {myaction (1); } [Aopiltest]Static voidMain (string[] args) {Console.WriteLine ("I'm the Main method ."); Maintest MT=Newmaintest (); Mt. Myaction+=mt_myaction; Mt. Call (); } [Aopiltest]Static voidMt_myaction (inti) {Console.WriteLine ("I am action, my value is:"+i); } }}
The best injection method of AOP--msil injection