Delegate 与 MulticastDelegate 委托的单波与多波模式
2009-03-04 00:01
351 查看
class TestDelegate { public delegate void EventHanding(); public event EventHanding OnFireEvnet; protected void RegistEvent() { Delegate d1 = new EventHanding(test1); Delegate d2 = new EventHanding(test2); Delegate d3 = new EventHanding(test3); Delegate d4 = new EventHanding(test4); Delegate newEvent1 = Delegate.Combine(d1, d2); Delegate newEvent2 = Delegate.Combine(d3, d4); //新合并的委托是一个新的对象 if (Object.ReferenceEquals(d2, newEvent1)) { string str = string.Empty; } if (d2.Method.ToString().CompareTo(newEvent1.Method.ToString())==0) { string str = string.Empty; } EventHanding newEvent = (EventHanding)Delegate.Combine(newEvent1, newEvent2); OnFireEvnet += newEvent; } protected void FireEvent() { //单波 MulticastDelegate del = (MulticastDelegate)OnFireEvnet; del.Method.Invoke(this, null); //多波 OnFireEvnet(); } int i = 0; public void test1() { i++; } public void test2() { i++; } public void test3() { i++; } public void test4() { i++; } public static void Test() { TestDelegate test = new TestDelegate(); test.RegistEvent(); test.FireEvent(); } }
相关文章推荐
- Delegate 与 MulticastDelegate 委托的单波与多波模式
- Delegate 与 MulticastDelegate 委托的单波与多波模式
- 观察者模式(observer)之委托(delegate) c#简单例子
- 如何理解 iOS Delegate (委托)设计模式 .
- Strategy模式与Delegate委托
- 如何理解 iOS Delegate (委托)设计模式
- 类的继承,类的密封sealed,类的抽象abstrac,virtual虚化和复写,oveload重载,delegate委托,单例模式
- iOS设计模式——委托(delegate)
- Kotlin学习(十八): 委托模式(Delegate)和委托属性(Delegate Properties)
- iOS设计模式——委托(delegate)
- iOS设计模式——委托(delegate)
- iOS设计模式——委托(delegate)
- Observer模式,delegate(委托)模式
- delegate代理(委托)设计模式
- Objective_C的语言特性,以及委托模式delegate
- 使用蓝图(Blueprint)绑定多播委托(Multicast Delegate)【UE4】【C++】
- IOS-设计模式之委托(delegate)
- iOS 多播委托(GCDMulticastDelegate)
- iOS设计模式——委托(delegate)
- GCDMulticastDelegate多播委托