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 MethodInfo method_info;
28 protected Delegate (object target, string method)
31 throw new ArgumentNullException (Locale.GetText ("Target object is null"));
34 throw new ArgumentNullException (Locale.GetText ("method name is null"));
36 this.target_type = null;
37 this.method_ptr = IntPtr.Zero;
38 this.m_target = target;
39 this.method_name = method;
42 protected Delegate (Type target_type, string method)
45 throw new ArgumentNullException (Locale.GetText ("Target type is null"));
48 throw new ArgumentNullException (Locale.GetText ("method string is null"));
50 this.target_type = target_type;
51 this.method_ptr = IntPtr.Zero;
53 this.method_name = method;
56 public MethodInfo Method {
62 public object Target {
72 public object DynamicInvoke( object[] args )
74 return DynamicInvokeImpl( args );
77 public virtual object DynamicInvokeImpl( object[] args )
79 return Method.Invoke( m_target, args );
82 public virtual object Clone()
84 return MemberwiseClone();
87 public override bool Equals (object o)
92 if ( o.GetType() != this.GetType() )
95 Delegate d = (Delegate) o;
96 if ((d.target_type == target_type) &&
97 (d.m_target == m_target) &&
98 (d.method_name == method_name) &&
99 (d.method_ptr == method_ptr))
105 public override int GetHashCode ()
107 return (int)method_ptr;
110 // This is from ISerializable
112 public void GetObjectData (SerializationInfo info, StreamingContext context)
114 // TODO: IMPLEMENT ME
117 public virtual Delegate[] GetInvocationList()
119 return new Delegate[] { this };
123 /// Returns a new MulticastDelegate holding the
124 /// concatenated invocation lists of MulticastDelegates a and b
126 public static Delegate Combine (Delegate a, Delegate b)
136 if (a.GetType () != b.GetType ())
137 throw new ArgumentException (Locale.GetText ("Incompatible Delegate Types"));
139 return a.CombineImpl (b);
143 /// Returns a new MulticastDelegate holding the
144 /// concatenated invocation lists of an Array of MulticastDelegates
146 public static Delegate Combine( Delegate[] delegates )
148 Delegate retval = null;
150 foreach ( Delegate next in delegates ) {
151 retval = Combine( retval, next );
158 protected virtual Delegate CombineImpl (Delegate d)
160 throw new MulticastNotSupportedException ("");
164 public static Delegate Remove( Delegate source, Delegate value) {
165 if ( source == null )
171 throw new NotImplementedException ();
175 protected virtual Delegate RemoveImpl(Delegate d)
177 throw new NotImplementedException();
180 public static bool operator ==( Delegate a, Delegate b )
182 if ((object)a == null) {
183 if ((object)b == null)
187 return a.Equals( b );
190 public static bool operator !=( Delegate a, Delegate b )