예제 #1
0
파일: Advisor.cs 프로젝트: mayleng/AOP
        public object Invoke(IMethodInvocation invocation)
        {
            IKnight knight = invocation.Target as IKnight;  // 取得骑士

            this.Minstrel.singBefore(knight);               // 前置通知
            object result = invocation.Proceed();

            this.Minstrel.singAfter(knight);                // 后置通知

            return(result);
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            IApplicationContext context = new XmlApplicationContext("~/objects.xml");

            IKnight knight = context.GetObject("knight") as IKnight;

            knight.embarkOnQuest();

            Thread.Sleep(10);
            // 创建代理工厂
            ProxyFactory pf = new ProxyFactory(knight);
            // 创建代理对象
            IKnight ic = pf.GetProxy() as IKnight;

            Response.Write(ic.GetType());
            Response.Write("<br/>");
            Response.Write(ic.Name);
            ic.embarkOnQuest();
        }
예제 #3
0
파일: Minstrel.cs 프로젝트: mayleng/AOP
 public string  singAfter(IKnight knight)
 {
     return("Tee-hee-he; Sir " + knight.Name + " did embark on a quest!");
 }
예제 #4
0
파일: Minstrel.cs 프로젝트: mayleng/AOP
 public string singBefore(IKnight knight)
 {
     return("Fa la la; Sir " + knight.Name + " is so brave!");
 }
예제 #5
0
 public KnightAdapter(IKnight knight)
 {
     Knight = knight;
 }
예제 #6
0
 public Knight(IKnight other) :
     base(other)
 {
 }
예제 #7
0
 public Knight(IKnight other) :
     base(other)
 {
     SpriteImageFilePath = DefaultSpriteImageFiles[this.Color];
 }
예제 #8
0
 public KnightInTraining()
 {
     // in this example our proxy creates and wraps a subject
     // but a reference to a subject could also be passed in
     _subject = new Knight();
 }