zoukankan      html  css  js  c++  java
  • 切面编程AOP之KingAOP

    1. 在Nuget上安装KingAOP

    2. 创建一个新的类

    public class Test : IDynamicMetaObjectProvider
        {
            public DynamicMetaObject GetMetaObject(Expression paramter)
            {
                return new AspectWeaver(paramter, this);
            }
    
            [LogAspec]
            public void Operate()
            {
                Console.WriteLine("Call 'Test类' - ‘Operate方法’");
            }
        }
    
        public class LogAspec : OnMethodBoundaryAspect
        {
            public override void OnEntry(MethodExecutionArgs args)
            {
                Console.WriteLine("OnEntry: Hello KingAOP");
            }
    
            public override void OnException(MethodExecutionArgs args)
            {
                Console.WriteLine("OnException: Hello KingAOP");
            }
    
            public override void OnSuccess(MethodExecutionArgs args)
            {
                Console.WriteLine("OnSuccess: Hello KingAOP");
            }
    
            public override void OnExit(MethodExecutionArgs args)
            {
                Console.WriteLine("OnExit: Hello KingAOP");
            }
        }
    

      

    3 在控制台中调用该类 (实践后发现,如果需要用KingAop进行横向切面则必须在实例化切面的类时用动态类型dynamic接收)

    static void Main(string[] args)
            {
                #region kingAOP
                dynamic test = new Test();
                try
                {
                    Console.WriteLine("Call Mian ..");
                    test.Operate();
                    Console.WriteLine("Exit Main ..");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                Console.Read();
                #endregion
            }
    

      

  • 相关阅读:
    java中Logger.getLogger(Test.class),即log4日志的使用
    System.getProperty()方法大全 (转载)
    常用MySQL函数
    MYSQL常用命令(转载)
    Oracle中与日期时间有关的运算函数
    R
    珍惜现在,感恩生活 多重背包
    Piggy-Bank 完全背包
    骨骼收集器01背包
    D
  • 原文地址:https://www.cnblogs.com/zxhome/p/10730004.html
Copyright © 2011-2022 走看看