//接收報紙(多家報社,想知道是來自哪家報社報紙) public void ReceiveNewspaper2(Object sender, PublisherArgs newspaper) { if (sender is Publisher_MulticastDelegate) { newspaper.Newspaper.PublisherName = (sender as Publisher_MulticastDelegate).Name; } if (sender is Publisher_MulticastDelegate2) { newspaper.Newspaper.PublisherName = (sender as Publisher_MulticastDelegate2).Name; } this.Newspaper = newspaper.Newspaper; }
//寄送報紙(多家報社) public void SendNewspaper2(Newspaper_MulticastDelegete newspaper) { //使用委託 if (_Subscribers2 != null) { //_Subscribers(newspaper); //如果在多播委託時產生例外: //將_Subscribers中的調用委託函數列表迭代出來 foreach (Subscribers2 hander in _Subscribers2.GetInvocationList()) { try { //每一個元素都是Subscribers類型函數,調用hander(調用Subscribers2()的當前類,參數); hander(this, new PublisherArgs(new Newspaper_MulticastDelegete())); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }
//寄送報紙 public void SendNewspaper(Newspaper_MulticastDelegete newspaper) { newspaper.PublisherName = this.Name; //使用委託 if (_Subscribers != null) { //_Subscribers(newspaper); //如果在多播委託時產生例外: //將_Subscribers中的調用委託函數列表迭代出來 foreach (Subscribers hander in _Subscribers.GetInvocationList()) { try { //每一個元素都是Subscribers類型函數,調用hander(參數); hander(newspaper); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }
public PublisherArgs(Newspaper_MulticastDelegete newspaper) { this.Newspaper = newspaper; }
//接收報紙 public void ReceiveNewspaper(Newspaper_MulticastDelegete newspaper) { this.Newspaper = newspaper; }