I have a toy AOP static weaver: YAAOPF.
It does not support around advice, but before
advice can force the call to be skipped, which
is just as good.
It apparently does not work for private methods
(I guess I could fix that).
Demo:
C:\Work\dnaop>type SomeLib.cs
using System;
namespace SomeLib
{
public class SomeClass
{
public void X()
{
Console.WriteLine("X");
}
public void M1()
{
Console.WriteLine("M1");
}
public void M2()
{
Console.WriteLine("M2 before");
X();
Console.WriteLine("M2 after");
}
public void M3()
{
Console.WriteLine("M3");
}
}
}
C:\Work\dnaop>csc /t:library SomeLib.cs
Microsoft (R) Visual C# Compiler version 3.5.0-beta4-20153-05 (20b9af91)
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Work\dnaop>type Program.cs
using System;
using SomeLib;
namespace MyApp
{
public class Program
{
public static void Main(string[] args)
{
SomeClass o = new SomeClass();
o.M1();
o.M2();
o.M3();
}
}
}
C:\Work\dnaop>csc /r:SomeLib.dll Program.cs
Microsoft (R) Visual C# Compiler version 3.5.0-beta4-20153-05 (20b9af91)
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Work\dnaop>Program
M1
M2 before
X
M2 after
M3
C:\Work\dnaop>type Patch.cs
using System;
using Vajhoej.StaticWeaver;
namespace Hack
{
[Aspect]
public class Patch
{
[Pointcut(Signature="* SomeLib.SomeClass::X(*)")]
public static void MethodToPatch() { }
[BeforeCallAdvice(Pointcut="MethodToPatch")]
public static void SkipX(MethodJoinpoint mjp)
{
Console.WriteLine("Let us skip the call to X");
mjp.SkipCall = true;
}
}
}
C:\Work\dnaop>csc /r:StaticWeaver.dll /t:library Patch.cs
Microsoft (R) Visual C# Compiler version 3.5.0-beta4-20153-05 (20b9af91)
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Work\dnaop>call yaaopf1 SomeLib.dll Patch.dll Glue.dll
C:\Work\dnaop>Program
M1
M2 before
Let us skip the call to X
M2 after
M3
Arne