imported delegate patches from Daniel, new GetHashCode icalls
[mono.git] / mcs / class / corlib / System / MulticastDelegate.cs
1 //
2 // System.MultiCastDelegate.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Daniel Stodden (stodden@in.tum.de)
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 //
10 // TODO: Remove Missing
11 //
12
13 using System.Globalization;
14
15 namespace System {
16
17         public abstract class MulticastDelegate : Delegate
18         {
19                 private MulticastDelegate prev;
20
21                 protected MulticastDelegate (object target, string method)
22                         : base (target, method)
23                 {
24                         prev = null;
25                 }
26
27                 protected MulticastDelegate (Type target_type, string method)
28                         : base (target_type, method)
29                 {
30                         prev = null;
31                 }
32
33 #if NOTYET
34                 private MulticastDelegate (Type target_type, string method, Delegate [] list)
35                         : base (target_type, method)
36                 {
37                         invocation_list = (Delegate[])list.Clone ();
38                 }
39 #endif
40                 
41 #if NOTYET
42                 public MethodInfo Method {
43                         get {
44                                 return null;
45                         }
46                 }
47 #endif
48
49                 public override object DynamicInvokeImpl( object[] args )
50                 {
51                         if ( prev != null )
52                                 prev.DynamicInvokeImpl( args );
53
54                         return base.DynamicInvokeImpl( args );
55                 }
56
57                 // <remarks>
58                 //   Equals: two multicast delegates are equal if their base is equal
59                 //   and their invocations list is equal.
60                 // </remarks>
61                 public override bool Equals (object o)
62                 {
63                         if ( ! base.Equals( o ) )
64                                 return false;
65
66                         MulticastDelegate d = this;
67                         MulticastDelegate c = (MulticastDelegate) o;
68                         do {
69                                 if ( d != c )
70                                         return false;
71                                 
72                                 c = c.prev;
73                                 d = d.prev;
74                         } while ( (object)d != null );
75                 
76                         if ( (object)c == null )
77                                 return true;
78
79                         return false;
80                 }
81
82                 //
83                 // FIXME: This could use some improvements.
84                 //
85                 public override int GetHashCode ()
86                 {
87                         return base.GetHashCode ();
88                 }
89                 
90                 // <summary>
91                 //   Return, in order of invocation, the invocation list
92                 //   of a MulticastDelegate
93                 // </summary>
94                 public override Delegate[] GetInvocationList()
95                 {
96                         throw new NotImplementedException();
97                 }
98
99                 // <summary>
100                 //   Combines this MulticastDelegate with the (Multicast)Delegate `follow'.
101                 //   This does _not_ combine with Delegates. ECMA states the whole delegate
102                 //   thing should have better been a simple System.Delegate class.
103                 //   Compiler generated delegates are always MulticastDelegates.
104                 // </summary>
105                 protected override Delegate CombineImpl( Delegate follow )
106                 {
107                         MulticastDelegate combined, orig, clone;
108                         
109                         if ( this.GetType() != follow.GetType() )
110                                 throw new ArgumentException( Locale.GetText("Incompatible Delegate Types") );
111
112                         combined = (MulticastDelegate)follow.Clone();
113
114                         for ( clone = combined, orig = ((MulticastDelegate)follow).prev;
115                               (object)orig != null; orig = orig.prev ) {
116
117                                 clone.prev = (MulticastDelegate)orig.Clone();
118                                 clone = clone.prev;
119                         }
120
121                         clone.prev = (MulticastDelegate)this.Clone();
122
123                         for ( clone = clone.prev, orig = this.prev;
124                               (object)orig != null; orig = orig.prev ) {
125
126                                 clone.prev = (MulticastDelegate)orig.Clone();
127                                 clone = clone.prev;
128                         }
129
130                         return combined;
131                 }
132
133                 protected override Delegate RemoveImpl( Delegate value )
134                 {
135                         throw new NotImplementedException();
136                 }
137         }
138 }