5 // Miguel de Icaza (miguel@ximian.com)
6 // Daniel Stodden (stodden@in.tum.de)
8 // (C) Ximian, Inc. http://www.ximian.com
10 // TODO: Mucho left to implement
14 using System.Globalization;
15 using System.Reflection;
16 using System.Runtime.Serialization;
21 public abstract class Delegate : ICloneable, ISerializable {
22 protected Type target_type;
23 protected object m_target;
24 protected string method_name;
25 protected IntPtr method_ptr;
26 protected IntPtr delegate_trampoline;
27 protected MethodInfo method_info;
29 protected Delegate (object target, string method)
32 throw new ArgumentNullException (Locale.GetText ("Target object is null"));
35 throw new ArgumentNullException (Locale.GetText ("method name is null"));
37 this.target_type = null;
38 this.method_ptr = IntPtr.Zero;
39 this.m_target = target;
40 this.method_name = method;
43 protected Delegate (Type target_type, string method)
46 throw new ArgumentNullException (Locale.GetText ("Target type is null"));
49 throw new ArgumentNullException (Locale.GetText ("method string is null"));
51 this.target_type = target_type;
52 this.method_ptr = IntPtr.Zero;
54 this.method_name = method;
57 public MethodInfo Method {
63 public object Target {
73 public object DynamicInvoke( object[] args )
75 return DynamicInvokeImpl( args );
78 public virtual object DynamicInvokeImpl( object[] args )
80 return Method.Invoke( m_target, args );
83 public virtual object Clone()
85 return MemberwiseClone();
88 public override bool Equals (object o)
93 if ( o.GetType() != this.GetType() )
96 Delegate d = (Delegate) o;
97 if ((d.target_type == target_type) &&
98 (d.m_target == m_target) &&
99 (d.method_name == method_name) &&
100 (d.method_ptr == method_ptr))
106 public override int GetHashCode ()
108 return (int)method_ptr;
111 // This is from ISerializable
113 public void GetObjectData (SerializationInfo info, StreamingContext context)
115 // TODO: IMPLEMENT ME
118 public virtual Delegate[] GetInvocationList()
120 return new Delegate[] { this };
124 /// Returns a new MulticastDelegate holding the
125 /// concatenated invocation lists of MulticastDelegates a and b
127 public static Delegate Combine (Delegate a, Delegate b)
137 if (a.GetType () != b.GetType ())
138 throw new ArgumentException (Locale.GetText ("Incompatible Delegate Types"));
140 return a.CombineImpl (b);
144 /// Returns a new MulticastDelegate holding the
145 /// concatenated invocation lists of an Array of MulticastDelegates
147 public static Delegate Combine( Delegate[] delegates )
149 Delegate retval = null;
151 foreach ( Delegate next in delegates ) {
152 retval = Combine( retval, next );
159 protected virtual Delegate CombineImpl (Delegate d)
161 throw new MulticastNotSupportedException ("");
165 public static Delegate Remove( Delegate source, Delegate value) {
166 if ( source == null )
172 throw new NotImplementedException ();
176 protected virtual Delegate RemoveImpl(Delegate d)
178 throw new NotImplementedException();
181 public static bool operator ==( Delegate a, Delegate b )
183 if ((object)a == null) {
184 if ((object)b == null)
188 return a.Equals( b );
191 public static bool operator !=( Delegate a, Delegate b )