AOP PostSharp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Laos;
using PostSharp;

namespace PostSharpApp
{
    [MyTrace(AttributeTargetMembers="Test*")]
    class Program
    {       
        static void Main(string[] args)
        {
            Test1();
            Test2();
            Foo();
            Console.ReadLine();
        }        
        static void Test1()
        {
            Console.WriteLine("Hello world! 1");
        }
        static void Test2()
        {
            Console.WriteLine("Hello world! 2");
        }
        static void Foo()
        {
            Console.WriteLine("Hello world! 3");
        }
    }

    [Serializable]
    class MyTrace : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            Console.WriteLine("Entering {0}", eventArgs.Method);
        }

        public override void OnExit(MethodExecutionEventArgs eventArgs)
        {
            Console.WriteLine("Exiting {0}", eventArgs.Method);
        }
    }
}
原文地址:https://www.cnblogs.com/shiningrise/p/5601704.html