Created
February 9, 2012 03:38
-
-
Save mgroves/1777078 to your computer and use it in GitHub Desktop.
SheepAspect Hello World
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 SheepAspect.Attributes; | |
| using SheepAspect.Runtime; | |
| namespace SheepAspectExample | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var obj = new MyClass(); | |
| obj.DoStuff(); | |
| } | |
| } | |
| public class MyClass | |
| { | |
| public void DoStuff() | |
| { | |
| Console.WriteLine("inside of DoStuff()"); | |
| } | |
| } | |
| [Aspect] | |
| public class HelloWorldAspect | |
| { | |
| [SelectMethods("Public & InType: 'SheepAspectExample.MyClass'")] | |
| public void MyPointcut() {} | |
| [Around("MyPointcut")] | |
| public object InterceptMethod(MethodJointPoint jp) | |
| { | |
| Console.WriteLine("Before {0}", jp.Method.Name); | |
| var result = jp.Execute(); | |
| Console.WriteLine("After {0}", jp.Method.Name); | |
| return result; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment