Thu Jan 3 23:24:04 CET 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System / Delegate.cs
1 //
2 // System.Delegate.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9 // TODO:  Mucho left to implement
10 //
11
12 using System;
13 using System.Globalization;
14 using System.Runtime.Serialization;
15
16 namespace System {
17
18         public abstract class Delegate : ICloneable, ISerializable {
19                 protected Type target_type;
20                 protected object m_target;
21                 protected string method;
22                 protected IntPtr method_ptr;
23
24                 protected Delegate (object target, string method)
25                 {
26                         if (target == null)
27                                 throw new ArgumentNullException (Locale.GetText ("Target object is null"));
28
29                         if (method == null)
30                                 throw new ArgumentNullException (Locale.GetText ("method name is null"));
31
32                         this.target_type = null;
33                         this.method_ptr = IntPtr.Zero;
34                         this.m_target = target;
35                         this.method = method;
36                 }
37
38                 protected Delegate (Type target_type, string method)
39                 {
40                         if (m_target == null)
41                                 throw new ArgumentNullException (Locale.GetText ("Target type is null"));
42
43                         if (method == null)
44                                 throw new ArgumentNullException (Locale.GetText ("method string is null"));
45
46                         this.target_type = target_type;
47                         this.method_ptr = IntPtr.Zero;
48                         this.m_target = null;
49                         this.method = method;
50                 }
51
52 #if NOTYET
53                 public MethodInfo Method {
54                         get {
55                                 return null;
56                         }
57                 }
58 #endif
59
60                 public object Target {
61                         get {
62                                 return m_target;
63                         }
64                 }
65
66
67                 //
68                 // Methods
69                 //
70
71                 public abstract object Clone ();
72
73                 public override bool Equals (object o)
74                 {
75                         if (!(o is System.Delegate))
76                                 return false;
77
78                         Delegate d = (Delegate) o;
79                         
80                         if ((d.target_type == target_type) &&
81                             (d.m_target == m_target) &&
82                             (d.method == method))
83                                 return true;
84
85                         return false;
86                 }
87
88                 public override int GetHashCode ()
89                 {
90                         return method.GetHashCode ();
91                 }
92
93                 // This is from ISerializable
94                 public void GetObjectData (SerializationInfo info, StreamingContext context)
95                 {
96                         // TODO: IMPLEMENT ME
97                 }
98
99                 public static Delegate Combine (Delegate a, Delegate b)
100                 {
101                         if (a == null){
102                                 if (b == null)
103                                         return null;
104                                 return b;
105                         } else 
106                                 if (b == null)
107                                         return a;
108
109                         if (a.GetType () != b.GetType ())
110                                 throw new ArgumentException (Locale.GetText ("Incompatible Delegate Types"));
111                         
112                         return a.CombineImpl (b);
113                 }
114
115                 protected virtual Delegate CombineImpl (Delegate d)
116                 {
117                         throw new MulticastNotSupportedException ("");
118                 }
119
120                 public static Delegate Remove( Delegate source, Delegate value) {
121                         throw new NotImplementedException ();
122                 }
123         }
124 }