C#用delegate实现AOP事务[C# | AOP | delegate]2011-07-10 博客园 农民伯伯前言上一篇 C# 用Attribute实现AOP事务 [C# | AOP | Attribute | ContextAttribute | IContributeObjectSink | IMessageSink ]是实现或者说达到AOP效果的一种方式,其实最早设计在C#中使用AOP来完成事务的方案是准备用delegate的,但无奈不习惯用 这个玩意,也理解不深,后来被Attribute吸引了,这个方案就搁浅了,不过现在我又回来了 : ) 正文我们先来看一段代码雏 形:
class TestClass
{
public void Test()
{
Console.WriteLine("Test");
}
public void DelegateTest(DelegateMethod dm)
{
Console.WriteLine("DelegateMethod Start");
dm.Invoke();
Console.WriteLine("DelegateMethod End");
}
}
class Program
{
static void Main(string[] args)
{
TestClass tc = new TestClass();
tc.Test();
Console.WriteLine("-------------------------------");
tc.DelegateTest(new DelegateMethod(mc.Test));
Console.Read();
}
}