Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created March 30, 2012 03:06
Show Gist options
  • Select an option

  • Save mgroves/2246117 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/2246117 to your computer and use it in GitHub Desktop.
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);
}
}
}
}
using System;
namespace WeavingExample
{
public class MyService
{
public void DoStuff()
{
Console.WriteLine("Inside of DoStuff");
}
}
}
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