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); }
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(); }
public string singAfter(IKnight knight) { return("Tee-hee-he; Sir " + knight.Name + " did embark on a quest!"); }
public string singBefore(IKnight knight) { return("Fa la la; Sir " + knight.Name + " is so brave!"); }
public KnightAdapter(IKnight knight) { Knight = knight; }
public Knight(IKnight other) : base(other) { }
public Knight(IKnight other) : base(other) { SpriteImageFilePath = DefaultSpriteImageFiles[this.Color]; }
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(); }