CleanAop使用笔记
前言,本(ˇˍˇ) 想用PostSharp做case,但是破解不成功,所以在github里找了一个CleanAop 地址: https://github.com/Jarvin-Guan/CleanAOP
目的是在Work类上加上日志
[AopIntercept] [PropertyNotifyIntercept] public class Work: Notice { [Logging] public virtual void DoWork(string Content) { System.Windows.Forms.MessageBox.Show(String.Format("{0}", Content), "提示"); } }
定义日志属性,这里偷懒了,没有定义日志类
public class Logging : CleanAopAttribute { public override void Before() { Debug.WriteLine("开始记录日志"); } public override void After(IInvocation invocation, Exception exp) { Debug.WriteLine("结束记录日志"); } public override void Middle(IInvocation invocation) { invocation.Proceed(); Debug.WriteLine("正在执行日志"); } }
调用Work类的DoWork方法
Work vm = InterceptClassFactory.GetInterceptClass<Work>(); vm.DoWork(textBox1.Text);