Created
March 30, 2012 03:06
-
-
Save mgroves/2246117 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Diagnostics; | |
| using System.Runtime.CompilerServices; | |
| namespace WeavingExample | |
| { | |
| public class MyService | |
| { | |
| [DebuggerNonUserCode, CompilerGenerated] | |
| internal sealed class <>z__Aspects | |
| { | |
| internal static readonly MyAspect a0; | |
| [CompilerGenerated] | |
| static <>z__Aspects() | |
| { | |
| MyService.<>z__Aspects.a0 = (MyAspect)<>z__AspectsImplementationDetails42858428.aspects1[0]; | |
| } | |
| } | |
| public void DoStuff() | |
| { | |
| MyService.<>z__Aspects.a0.OnEntry(null); | |
| try | |
| { | |
| Console.WriteLine("Inside of DoStuff"); | |
| MyService.<>z__Aspects.a0.OnSuccess(null); | |
| } | |
| catch (Exception CS$0$0__exception_26) | |
| { | |
| MyService.<>z__Aspects.a0.OnException(null); | |
| throw; | |
| } | |
| finally | |
| { | |
| MyService.<>z__Aspects.a0.OnExit(null); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace WeavingExample | |
| { | |
| public class MyService | |
| { | |
| public void DoStuff() | |
| { | |
| Console.WriteLine("Inside of DoStuff"); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using PostSharp.Aspects; | |
| namespace WeavingExample | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var obj = new MyService(); | |
| obj.DoStuff(); | |
| } | |
| } | |
| public class MyService | |
| { | |
| [MyAspect] | |
| public void DoStuff() | |
| { | |
| Console.WriteLine("Inside of DoStuff"); | |
| } | |
| } | |
| [Serializable] | |
| public class MyAspect : OnMethodBoundaryAspect | |
| { | |
| public override void OnEntry(MethodExecutionArgs args) | |
| { | |
| Console.WriteLine("before method"); | |
| } | |
| public override void OnException(MethodExecutionArgs args) | |
| { | |
| Console.WriteLine("exception"); | |
| } | |
| public override void OnExit(MethodExecutionArgs args) | |
| { | |
| Console.WriteLine("exit"); | |
| } | |
| public override void OnSuccess(MethodExecutionArgs args) | |
| { | |
| Console.WriteLine("success"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment